Mechanics of Encapsulation
Mechanics of Encapsulation
- Attribute values can be changed only by the operations provided by the object
- Operations are provided to access attribute values needed by clients
- The state of the object cannot be modified by clients directly
- Client code can only use operations in the interface
- Client code cannot “know” or take advantage of the implementation of an operation
- The implementation of an operation may change
- To fix a bug
- To improve performance
- To reflect a change in policy
- Client code will not be affected by changes in implementation
- Code maintenance and reuse become easier/less expensive