Understanding Encapsulation
Learn how data should be encapsulated within its object.
We'll cover the following...
Encapsulation
Object-oriented programming states that member data should be encapsulated within its object and that direct access to this data from the outside should be prevented. Let’s see why this is a critical concept in object orientation.
Encapsulation, also known as information hiding, is a concept where the object’s internal implementation is hidden from everything outside of the object. Encapsulation can be described in many ways. American computer engineers James Rumbaugh and Michael Blaha described it like this:
“One design goal is to treat classes as ‘black boxes,’ whose external interface is public but whose internal details are hidden from view. Hiding internal information permits implementation of a class to be changed without requiring any clients of the class to modify code.”
The vital key here is the interface. An interface is what we use to communicate with an object. Look at the remote controls in the figure above. The buttons we can push are the interface. We use them to communicate with the internal logic inside the device.
The remote control object is a “black ...