Java design principles-Interface Isolation principle (RPM)

Source: Internet
Author: User

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.

    • Customized Services

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.