Interface Isolation principle Interface segregation Principle
Defined:
- The client should not rely on interfaces it does not need
- Dependencies between classes should be based on the smallest interface
We can summarize these two definitions into one sentence: Create a single interface and don't build a bloated, bulky interface. A little more popular: interface as much as possible, and the interface of the method as little as possible.
Given to each module should be a single interface, provided to several modules should have several interfaces, rather than build a huge bloated interface, accommodating all client access.
Interface is the contract we provide when we design, we can prevent the proliferation of future changes and improve the flexibility and maintainability of the system by dispersing and defining multiple interfaces.
Meaning:
- The interface should be as small as possible
This is the core definition of the interface isolation principle, there is no bloated interface (Fat Interface), but the "small" is limited, the first is not to violate the principle of single responsibility.
When splitting an interface according to the principle of interface isolation, you must first meet the principle of single responsibility.
- interface to high cohesion
High cohesion is to improve the interface, class, module processing power, reduce external interaction.
Specific to the interface isolation principle is to require in the interface as little as possible to publish public methods, interface is the commitment of the external, the less commitment to the system development is more favorable, the risk of change will be less, but also conducive to reduce costs.
Custom service is to provide an individual with excellent service.
- There is a limit to the design of the interface
The smaller the design granularity of the interface, the more flexible the system, which is an indisputable fact. However, the flexibility has also brought about the complexity of the structure, the development difficulty increases, maintainability is reduced, this is not a project or product expected to see, so the interface design must pay attention to moderation, this degree can only be based on experience and common sense judgment, there is no cure or measurable standards.
Java design principles-Interface Isolation principle (RPM)