Contents    Page-10    Prev    Next    Page+10    Index   

Encapsulation with OOP

Object-oriented programming provides encapsulation: an external interface to an object in terms of messages is defined, but the internal implementation of the object is hidden.

Modularity: Objects are often a good way to think about the application domain.

Modifiability: The internal implementation of an object can be changed without modifying any other programs, as long as the external interface is maintained.

Expandability: New kinds of objects can be added to an existing system, as long as they present the same interface as existing objects.

To maintain encapsulation, it is good to make all accesses into messages, avoiding all direct accesses to instance variables: obj.getX() instead of obj.x