Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of interface isolation

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what is the principle of interface isolation". In daily operation, I believe that many people have doubts about what the principle of interface isolation is. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer your doubts about "what is the principle of interface isolation?" Next, please follow the editor to study!

What are the five principles of object-oriented design? -- principle of interface isolation

Principle of single responsibility (SRP: Single Pesponsibility Principle)

Interface isolation principle (ISP: Interface Segregation Principle)

Open-closed principle (OCP: Open-Close Principle)

Substitution principle (LSP: Liskov Substitution Principle)

Dependency inversion principle (DIP: De-pendence Inversion Principle)

What do they mean? Interface isolation principle: ISP

When designing an application, if a module contains multiple sub-modules, then we should be careful to abstract the module. Imagine that the module is implemented by a class, and we can abstract the system into an interface. However, when we need to add new modules or expand functions, the new module only contains some sub-modules in the original system, then the system will force us to implement all the methods in the interface, including some unnecessary methods. In this way, these behaviors may lead to bloated interface code, redundancy, and waste of resources.

To put it simply, every user should not be forced to implement interfaces that they will not use. Interfaces should be grouped in detail to ensure that each interface serves a sub-module.

Main points of ISP

The dependency of one class on another should be based on the smallest interface.

ISP does not require users to rely on methods they do not need, and the implementation class of the interface should be presented as a single responsibility role.

Reduce the interaction between users and users, and the changes and modifications of each user are independent.

Interface contamination

Using the delegate separation interface in the delegate pattern, two objects participate in processing the same request, and the object that receives the request delegates the request to another object to process, such as policy pattern, proxy pattern and so on.

Using multiple inheritance to separate interfaces

Overbloated interface design is a pollution to the interface. The so-called interface pollution is to add unnecessary responsibilities to the interface, which brings difficulties in maintenance and poor reusability to the interface.

"Interface isolation" is actually the principle of customized service design. Multiple inheritance of interfaces is used to realize the combination of different interfaces, so as to provide component services to the outside world and provide services on demand.

For interface contamination, consider the following treatment methods

At this point, the study of "what is the principle of interface isolation" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report