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

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces what are the design principles of the design pattern, the article introduces in great detail, has a certain reference value, interested friends must read it!

Six principles of design pattern: 1, single principle; 2, Richter replacement principle; 3, dependence inversion principle; 4, interface isolation principle; 5, Dimitt principle; 6, opening and closing principle.

Six principles of design pattern:

1. Single principle (Single Responsibility Principle): a class or method is responsible for only one responsibility, and try to make the change caused by only one behavior reason of the class.

A, business object (BO business object), business logic (BL business logic) split

2. Richter substitution principle (LSP liskov substitution principle): subclasses can expand the function of the parent class, but cannot change the function of the original parent class; (the essence is actually the polymorphism of C++)

(purpose: to enhance the robustness of the program) in the actual project, each subclass corresponds to a different business meaning, making the parent class as a parameter, passing different subclasses to complete different business logic.

3. Dependency inversion principle (dependence inversion principle): interface-oriented programming; (implementation of application scenarios through interfaces as parameters)

An abstraction is an interface or an abstract class, and the details are the implementation class

Meaning:

The upper module should not rely on the lower module, and both should rely on its abstraction.

Abstraction should not depend on details, details should rely on abstractions.

The popular point is to say that variables or pass parameters, try to use abstract classes, or interfaces

[interfaces are responsible for defining public properties and methods, and declaring dependencies with other objects, abstract classes are responsible for the implementation of the common construction part, and the implementation classes accurately implement business logic]

4. Interface isolation principle (interface segregation principle): establish a single interface; (expanding to a class is also an interface, and everything is an interface)

Definition:

a. The client should not rely on interfaces it does not need

b. Dependencies between classes should be based on the smallest interface

Simple understanding: complex interfaces are split into multiple simple interfaces according to the business; (for the split of some businesses, take a look at the application of the adapter)

[the smaller the design granularity of the interface is, the more flexible the system is, but the more flexible the structure is, the more difficult the development will be and the lower the maintainability will be]

5. Dimitt principle (law of demeter LOD): the least known principle to minimize the coupling between classes.

An object should know the least about other objects.

6. Open-close principle (open closed principle): build the architecture with abstraction and implement the extension principle.

The above is all the contents of the article "what are the design principles of design patterns". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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

Internet Technology

Wechat

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

12
Report