ISP-interface segregation principle)

Source: Internet
Author: User
It is better to use multiple dedicated interfaces than to use a single total interface.
The dependence of a class on another class should be based on the smallest interface.
An interface represents a role and should not assign different roles to an interface. Unrelated interfaces are merged to form a bloated large interface, which is a pollution to roles and interfaces. "Customers should not be forced to rely on methods they do not need. An interface belongs to a customer and does not belong to its class hierarchy ." This is quite clear. In other words, do not force customers to use the methods they do not use. If you force users to use the methods they do not use, then these customers will face the changes caused by the changes to these unused methods. Ii. Example: Reference Design: In this design, withdrawals, deposits, and transfers all use a common interface. That is to say, each class is forced to rely on the interface methods of the other two classes, therefore, each class may be affected by the methods of the other two classes (not related to itself. For withdrawal, it does not care about "deposit operations" or "transfer operations" at all, but it is affected by the changes in these two methods.

So how can we solve this problem? For reference design, a dedicated operation interface is designed for each class so that they only depend on the methods of their relationship, so that they will not affect each other!
Iii. Implementation Method:

1. Use the delegate separation Interface
2. Use multiple inheritance and separation Interfaces

 

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.