Encapsulation

Synonym: information hiding

 

Encapsulation is one of the most important characteristics of an object oriented system.

 

Booch describes encapsulation as

"The process of hiding all of the details of an object that do not contribute to its essential characteristics; typically, the structure of an object is hidden, as well as the implementation of its methods. [...]"

[BOO91, p. 513]

Encapsulation of variables in object MyCar
Encapsulation of variables in object MyCar

As the figure of the object MyCar shows, all of its variables are enclosed inside the object's methods and may only be changed by those methods. As it is, when you want to accelerate a real-world car, you don't have to know exactly how the car's engine works. You just have to know that you have to step on the gas pedal and change the gear.

 

This leads to an easy-to-use interface, with benefits for the user, as well as for the developer:

 

» The user doesn't have to know details of the internal structure and functionality of an object. What he/she must know is, which operations can be done on the object to change its state.

» The developer can change or improve any implementation details, as long as the interface doesn't change. Another advantage is that all functionality is enclosed in the same object, what makes object handling easier.

 

As mentioned before, an object oriented system consists of "classes arranged in a class hierarchy". One class at the top of this hierarchy serves as the base for other classes, which should have the same or additional properties.

 

This process is called inheritance.

Neural Net Components in an Object Oriented Class Structure