Mastery
CS61B » Encapsulation

Basics

Module: set of methods that work together as a whole to perform some task or set of related tasks

Encapsulated module: its implementation is completely hidden, and it can be accessed only through a documented interface

Encapsulate by defining an interface through which the outside world can use, inspect, or manipulate it

Abstract data type (ADT) = encapsulated data structure

Not all encapsulated modules are ADTS; i.e. algorithms (like list sorters) and applications (like network routing software)

Way of preventing code tamperers from corrupting your data structures

Why It’s Great

1 The implementation is independent of functionality. You can implement a new version of the module or ADT independently. A new, better implementation can replace an old one

2 Encapsulation reduces debugging time

3 ADTs can guarantee that their invariants are preserved

4 Teamwork. Each programmer can independently implement a module without having access to the other modules. A large, complex programming project can be broken up into pieces

5 Documentation and maintainability. Bugs are easier to trace

Difference Between a Module and a Class

A module is organized around the functionality it provides. A class is organized around a data storage unit.