...
/Hiding Details and Creating the Public Interface
Hiding Details and Creating the Public Interface
Learn about the different concepts of data hiding in object-oriented programming.
We'll cover the following...
The key purpose of modeling an object in object-oriented design is to determine what the public interface of that object will be. The interface is the collection of attributes and methods that other objects can access to interact with that object. Other objects do not need, and in some languages are not allowed, to access the internal workings of the object.
Example
A common real-world example is television. Our interface to the television is the remote control. Each button on the remote control represents a method that can be called on the television object. When we, as the calling object, access these methods, we do not know or care if the television is getting its signal from a cable connection, a satellite dish, or an internet-enabled device. We don’t care what electronic signals are being sent to adjust the volume or whether the sound is destined for speakers or headphones. If we open the television to access its internal workings, for example, to split the output signal to both external speakers and a set of headphones, we may void the ...