Wednesday, October 27, 2010

What is Encapsulation?


Encapsulation is the process of packaging the base functionality of a class and providing access to the features of the class through a collection of behaviors. This means that the inner workings of the class are hidden from other classes and cannot be directly accessed.

Objects are responsible for maintaining their own state & behavior.

This means that a Sword object should not be able to directly manipulate a Player state and vice verse. For this reason, object state is hidden & behaviors may be created to allow external objects access and change state values.

Another way to refer to encapsulation is 'information hiding'.

No comments:

Post a Comment