current position:Home>Proposal of design pattern

Proposal of design pattern

2022-01-27 01:17:02 InfoQ

  Treat design patterns directly

1. Proposal of design pattern

1994 year ,  Four program practitioners co authored a book called 《 Design patterns - Reusable object-oriented software elements 》
Design Patterns -Elements of Reusable Object-Oriented software Books ‘
The concept of design pattern is put forward for the first time ;
summary
   Programming the interface , Instead of programming the implementation (  Programming for standards rather than implementation classes )
   Prefer object composition to inheritance


2. The cornerstone of design patterns :

   Inherit , encapsulation , polymorphic ;


3. Classification of design patterns

  • Creation type   Pattern (Creational patterns)
  • Structural type
  • Behavior type

From the definition --> establish ---> Behavioral ;

null

4. Seven principles of design pattern :( Need to consider )

  • Opening and closing principle :  Open to expansion , Turn off for changes
  • Richter's principle of substitution : Inherited parent class , Instead of changing the parent class (
    Subclasses generally do not override the methods of the parent class
  • Dependence leads to principle
    :   Interface oriented programming , Instead of implementing programming (  Abstractions should not depend on details , Detail depends on abstraction )
      Interface A,  It belongs to highly abstract matter
     Implementation class A1 It belongs to the class of detailed implementation
  If B1 To use A Information about ,  It can only be used A The interface of , Not the details A1;
 controller-->serveice( Implementation interface )
4.  Principle of single responsibility : Fine grained single functional class ,( Each class is only responsible for its own business )
5.
Interface isolation principle
:  Each class should have its own dedicated interface , Not a universal interface
6. Dimitar's law :
  Minimum knowledge principle ,  ( Two classes that do not require direct interaction ,  Interaction required , Use middleman )
  Excessive use of this principle , It will lead to the increase of intermediate classes , Reduced communication efficiency
7. Synthetic multiplexing principle :( Use as an attribute )
Priority combination   Secondly, inheritance
    Combine :  such as A There are to be used in B The method in ,  It's usually inheritance , But for good scalability ,
We can use it directly in A Create properties in , T B,  And then use B.4()

copyright notice
author[InfoQ],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270117008903.html

Random recommended