GRASP, SOLID, GOF, DRY, KISS, YAGNI, LOD design patterns and principles

GRASP: General Responsibility Assignment Software Patterns (9 types in total)

Tell us how to design the classes in the problem space and assign their behavioral responsibilities, and clarify the interrelationships between classes, etc.

  1. Infomation Expert
  2. Creator _
  3. Low coupling (low coupling)
  4. High cohesion (high cohesion)
  5. Controller _
  6. Polymorphism
  7. Pure Fabrication
  8. Indirection
  9. Protected Variations

SOLID: Design principles (5 types in total)

  1. Single Responsibility Principle ( SRP )
  2. Open Closed Principle ( OCP )
  3. Liskov Substitution Principle ( LSP )
  4. Interface Segregation Principle ( ISP )
  5. Dependency Inversion Principle ( DIP )

GOF: Design Patterns (23 in total)

  1. Singleton mode: A class can only generate one instance, which provides a global access point for external access to the instance, and its extension is the limited multiple instance mode.
  2. Prototype mode: use an object as a prototype, and clone multiple new instances similar to the prototype by copying it.
  3. Factory Method (Factory Method) mode: Define an interface for creating products, and subclasses decide what products to produce.
  4. Abstract Factory (AbstractFactory) mode: Provide an interface to create a product family, each of its subclasses can produce a series of related products.
  5. Builder (Builder) mode: decompose a complex object into multiple relatively simple parts, then create them separately according to different needs, and finally build the complex object.
  6. Proxy mode: Provide a proxy for an object to control access to the object. That is, the client accesses the object indirectly through the proxy, thereby restricting, enhancing or modifying some characteristics of the object.
  7. Adapter (Adapter) mode: convert the interface of a class into another interface that the customer wants, so that those classes that could not work together due to interface incompatibility can work together.
  8. Bridge pattern: Separates abstraction from implementation so that they can vary independently. It is implemented by replacing the inheritance relationship with the composition relationship, thereby reducing the coupling degree of the two variable dimensions of abstraction and implementation.
  9. Decorator mode: Dynamically add some responsibilities to the object, that is, add its additional functions.
  10. Facade mode: Provide a consistent interface for multiple complex subsystems, making these subsystems easier to access.
  11. Flyweight mode: Use sharing technology to effectively support the reuse of a large number of fine-grained objects.
  12. Composite mode: Composes objects into a tree-like hierarchy, enabling users to have consistent access to individual objects and composite objects.
  13. Template Method (TemplateMethod) mode: define the algorithm skeleton in an operation, and delay some steps of the algorithm to the subclass, so that the subclass can redefine some specific steps of the algorithm without changing the structure of the algorithm.
  14. Strategy (Strategy) mode: defines a series of algorithms and encapsulates each algorithm so that they can be replaced with each other, and the change of the algorithm will not affect the customers who use the algorithm.
  15. Command mode: Encapsulate a request as an object, so that the responsibility for issuing the request is separated from the responsibility for executing the request.
  16. Chain of Responsibility (Chain of Responsibility) pattern: The request is passed from one object in the chain to the next object until the request is responded to. In this way the coupling between objects is removed.
  17. State (State) pattern: Allows an object to change its behavior when its internal state changes.
  18. Observer (Observer) mode: There is a one-to-many relationship between multiple objects. When an object changes, it notifies other multiple objects of this change, thereby affecting the behavior of other objects.
  19. Mediator mode: Define an intermediary object to simplify the interaction relationship between original objects, reduce the coupling degree between objects in the system, and make the original objects do not need to understand each other.
  20. Iterator mode: Provides a way to sequentially access a series of data in an aggregate object without exposing the internal representation of the aggregate object.
  21. Visitor mode: Provide multiple access methods for each element in a collection without changing the collection elements, that is, each element has multiple visitor objects to visit.
  22. Memento pattern: Get and save an object's internal state so that it can be restored later without breaking encapsulation.
  23. Interpreter (Interpreter) mode: Provides how to define the grammar of the language, and the method of interpreting language sentences, that is, the interpreter.

Other essential design principles:

DRY - Don't Repeat Yourself
    Don't repeat yourself: Try to reduce repeated lines of code, repeated methods, and repeated modules in the project.

KISS - Keep It Simple & Stupid
    Keep it simple and easy to understand: realize complex things "simplely". We should work on code comprehensibility, reduce complexity, and make maintenance easy.
    "Any idiot can write a program that a computer can understand, but a good programmer is only one who can write a program that a human can easily understand."

YAGNI - You Ain't Gonna Need It
    
You will not need it: Do not over-design. The cost of design is very high. This kind of over-design will not only delay the speed of development iterations, but also its benefits are very low.

LOD - Law of Demeter
    
Dimiter's law: the principle of minimum knowledge. An object should have the least understanding of other objects. In layman's terms, the less a class knows about the classes it depends on, the better. That is, the methods that are exposed to the outside world should be as few as possible for the dependent classes.


reference:

Various design patterns explain the website

GRASP Design Principles

Understanding of the three principles of DRY, KISS, and YAGNI

Talking about the Specific Application of SOLID Principles

GOF 23 Design Patterns Essence

Guess you like

Origin blog.csdn.net/xiaoxiong_jiaxin/article/details/119411704