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 are the principles of design patterns?

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "what are the principles of design patterns". In daily operation, I believe that many people have doubts about what the principles of design patterns are. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the principles of design patterns?" Next, please follow the editor to study!

Brief introduction

Design patterns are based on some form of best practices, which can better achieve code reuse, easier to understand and more reliable. Each design pattern correspondingly describes a class of recurring problems and core solutions.

Types

Create a model

Only provide the creation method without showing the creation logic, and do not instantiate the object directly using the new keyword to determine the type of object that needs to be provided according to the requirements.

Specific patterns: factory pattern (Factory Pattern), Abstract Factory pattern (Abstract Factory Pattern), Singleton pattern (Singleton Pattern), Builder pattern (Builder Pattern), prototype pattern (Prototype Pattern).

Structural model

Class structure model and object structure model, class structure model uses inheritance mechanism to organize interfaces and classes, and object structure model uses composition and aggregation to combine objects. Meet the principle of synthetic reuse.

Specific patterns: adapter pattern (Adapter Pattern), bridging pattern (Bridge Pattern), filter pattern (Filter, Criteria Pattern), combination pattern (Composite Pattern), decorator pattern (Decorator Pattern), appearance pattern (Facade Pattern), shared meta pattern (Flyweight Pattern), proxy mode (Proxy Pattern).

Behavioral model

Describe the complex process control when the program is running, that is, to cooperate with multiple objects to complete the tasks that a single object cannot accomplish, and to design algorithms and assign responsibilities between objects. Specific patterns: chain of responsibility pattern (Chain of Responsibility Pattern), command mode (Command Pattern), interpreter pattern (Interpreter Pattern) iterator pattern (Iterator Pattern), mediator pattern (Mediator Pattern), memo pattern (Memento Pattern), observer pattern (Observer Pattern), state pattern (State Pattern), empty object pattern (Null Object Pattern), policy pattern (Strategy Pattern), template pattern (Template Pattern), visitor pattern (Visitor Pattern).

Principle

Opening and closing principle

Open extensions, turn off modifications, use interfaces and abstract classes, the key step is abstraction.

Richter's substitution principle

A base class can be a subclass, which is an abstract specification.

Dependence reversal principle

Program against the interface.

Interface isolation principle

Multiple isolated interfaces are better than a single interface, reducing the coupling between classes.

Know the principle at least

Entities should interact with other entities as little as possible.

Synthetic multiplexing

Try to use composition and aggregation instead of inheritance.

At this point, the study of "what are the principles of design patterns" 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