Java design mode (13) interface Isolation principle (ISP)

Source: Internet
Author: User
Tags what interface

Interface Isolation principle (Interface segregation Principle) ISP Basic Concept interface
    • instance Interface (Object Interface): An instance object of a class is a description of a type of thing, an interface.
    • class Interface: The interface of Interface key definitions in Java, the narrow interface we usually understand
ISP definition
    • The client (module) should not rely on the interface it does not need ( the purity of the interface )

      A module should rely on the interface it needs, what interface is required to provide what interface, the unnecessary interface is removed, it needs to refine the interface, to ensure the purity of the interface

    • Dependencies between classes should be based on the smallest interface

      The same emphasis on the refinement of the interface, then the interface as an abstraction, in the establishment of a relationship to ensure that the purity will not be dependent on the destruction of irrelevant

Guarantee Interface PurityThe specification
    • Interface Refinement

      Without violating the single-Responsibility principle (SRP) , to be as thin as possible on the interface, violating the SRP would result in a single module exposing too many methods ( the methods in the interface are Publi), and many of the internal interfaces of a single function are exposed.

    • Interface High cohesion

      • High cohesion : improve the processing power of interfaces, classes, modules, and reduce external interaction.
      • Interface is a commitment to the external, the less commitment to the development of the system is more favorable, the risk of change is also smaller, but also conducive to reduce costs.
    • Module Service customization

      To reduce the coupling between modules, you can customize the service for similar functions between modules (not sharing interfaces, but using specialized interfaces)

Guaranteed interface Atomic NatureThe specification
    • One interface serves only one submodule or business logic
    • Compress public methods by optimizing business logic
The size of the interface is too small, resulting in an increase in the number of interfaces, unfriendly to the developer, the size of the interface is too large, the flexibility is reduced, can not provide customized services to the overall project to create an unpredictable risk. Example ISP

Define a scene, that is, when you are looking for a job, the screening of resumes, people have specificity, if the interface of the grain through the large, it may not be able to make a full presentation of the skills, or have to brag to ensure that all of their skills are involved ( because the granularity is not refined ), may also be divided Interface fine spent in large , fill resume and write a book the same cost, where there will be someone to apply for, to sell the book is not good ~ it is not realized, completely without any code difficulty ....

Often the granularity of the interface is inappropriate and the scene is closely related, it depends on the designer's ability, and some design patterns are widely used and their interface design is just right.

Java design mode (13) interface Isolation principle (ISP)

Related Article

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.