Information Hiding is the practice of hiding the details of a module with the goal of controlling access to the details from the rest of the system.
- Most of the design methods are based on decomposing a problem-solution into modules.
- Module mean a cohesive system subunit that performs a share of the work.
- In Java, the primary module mechanism is the class. Decomposing a system into modules helps us manage complexity.
- Additionally, the modules can form the basis of assignments for different programming teams working separately on a large system.
- Modules act as an abstraction tool. The complexity of their internal structure can be hidden from the rest of the system.
- This means that the details involved in implementing a module are isolated from the details of the rest of the system.
Because of following advantages of using Information Hiding, It is very much desirable:
- Information hiding helps manage the complexity of a system since a programmer can concentrate on one module at a time.
- As the different modules of program are interrelated & work together to solve the problem, Modules provide services to each other through a carefully defined interface.
- The interface in Java is usually provided by the public methods of a class. Programmers of one module do not need to know the internal details of the modules it interacts with, but they do need to know the interfaces.
- For example, Consider a driving analogy, you can start a car without knowing how many cylinders are in the engine. You do not need to know these lower-level details of the cars power subsystem in order to start it. You just have to understand the interface; that is, you only need to know how to turn the key.
- Similarly, you do not have to know the details of other modules as you design a specific module. Such a requirement would introduce a greater risk of confusion and error throughout the whole system.
- Information Hiding helps to manage the complexity of a large system, As well as support our quality goals of modifiability and reusability.
- In a well designed system, most modifications can be localized to just a few modules. Such changes are much easier to make than changes that permeate the entire system.
- A good system design results in the creation of generic modules that can be used in other systems.
- To achieve these goals of Modifiability and Reusability, modules should be good abstractions with strong cohesion; that is, each module should have a single purpose or identity and the module should stick together well.
- A cohesive module can usually be described by a simple sentence. If you have to use several sentences or one very convoluted sentence to describe your module, it is probably not cohesive.
- Each module should also exhibit information hiding so that changes within it do not result in changes in the modules that use it.
- This independent quality of modules is known as loose coupling. If your module depends on the internal details of other modules, it is not loosely coupled.