Information hiding
|
In computer science, the principle of information hiding is the hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. Protecting a design decision involves providing a stable interface which shields the remainder of the program from the implementation (the details that are most likely to change). In modern programming languages, the principle of information hiding manifests itself in a number of ways, including encapsulation and polymorphism.
A term encapsulation is often used interchangeably with information hiding, while some make distinctions between the two [1] (http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html). It seems that people, however, fail to agree on the distinctions between information hiding and encapsulation.
Information hiding reduces software development risk by shifting the code's dependency on an uncertain implementation (design decision) onto a well-defined interface. Clients of the interface perform operations purely through the interface so if the implementation changes, the clients do not have to change.
For example, if a three-dimensional point (x,y,z) is represented in a program with three floating point scalar variables and later, the representation is changed to a single array variable of size three, a module designed with information hiding in mind would protect the remainder of the program from such a change.
Information hiding serves as an effective criteria for modularization, dividing the program into independent, interchangeable modules. A conceptual example that illustrates this principle is the modularization of a car. One way to organize a car into modules might be: front (under-the-hood), middle (in the cabin), and rear (trunk). Another way to organize a car into modules might be: engine, transmission, steering, etc. Both are valid ways to decompose the car into modules, but the latter uses information hiding as a criteria for decomposition. In the example, we know that steering system details are likely to change. However, we also know there will be a steering system. We know what it will do, which allows us to define a stable interface to the steering system: a steering wheel.de:Datenkapselung fr:Encapsulation lt:Enkapsuliacija nl:Inkapseling pl:Enkapsulacja zh:信息隐藏