Study Notes (30): Chapter 2 Design Patterns of Architect's Inner Strength and Mind Method-Summary and Comparison of Design Patterns (Part 1)

Learn now: https://edu.csdn.net/course/play/28941/403587?utm_source=blogtoedu

1. Seven design principles:

1.1. Open and close principle (OCP): open for expansion, closed for modification = "Reduce maintenance brings new risks

1.2. Dependency inversion principle (DIP): The high-level does not rely on the bottom-level, and the abstraction is as much as possible = "Conducive to the upgrade and expansion of the code structure

1.3. Single Responsibility Principle (SRP): One class can only do one thing = "Easy to understand, improve code readability

1.4. Principle of Interface Isolation (ISP): One interface only does one thing = "Functional decoupling, high aggregation, low coupling

1.5. Law of Dimit (LOD): Know the principles at least, don’t know what you don’t know = "Reduce code bloat

1.6. The Richter's Substitution Principle (LSP): Subclass overrides the parent class method, and the function modification of the subclass cannot affect the meaning of the parent class method = "to prevent the spread of inheritance

1.7. The principle of composite reuse (CARP): try to use combination to achieve code reuse, do not use inheritance, such as injection = "reduce code coupling

2. Design mode:

2.1, pattern classification

2.1.1. Creation type: Factory method pattern> Abstract factory pattern> Builder pattern> Singleton pattern> Prototype pattern (usually use ready-made tool classes)

2.1.2 Structure type: Adapter mode> Decorator mode> Agency mode> Facade mode> Combination mode> Flyweight mode> Bridge mode

2.1.3 Behavioral type: Strategy mode> Observer mode> Chain of responsibility mode> Interpreter mode (regular expression)> Template mode> Iterator mode> Mediator mode> Command mode> Visitor mode> Memo mode> State mode

2.2. Mode summary

2.1. Factory model: product standardization, more efficient production = "The purpose is to encapsulate the creation details = "Real factory in life = "LoggerFactory, Calender in the source code

2.2. Singleton mode: unique instance = "The purpose is to ensure uniqueness = "CEO in life =" BeanFactory and Runtime in the source code

2.3. Prototype mode: Pull out a monkey's hair, blow out thousands of grandchildren = "Create objects efficiently, read memory directly without going through the construction method = "Clone in life =" ArrayList, PrototypeBean in the source code

2.4. Builder mode: random collocation = "The purpose is to open personality configuration steps = "Selection of ingredients in life = "StringBuilder, BeanDefinitionBuilder in the source code

2.5. Proxy mode: there is no resources and no time, you have to find a matchmaker to help = "The purpose is to enhance the responsibilities =" similar to the matchmaker in life = "ProxyFactoryBean, JdkDynamicAopProxy in the source code

2.6. Facade mode: Open a door and go to the world => The purpose is to have a unified access to the entrance = "Reception in life = "jdbcUtils, RequestFacade

2.7. Decorator mode: his eldest uncle and his second uncle are his uncles = "The purpose is to expand flexibly and have the same origin = "No matter what side dishes or pancakes are added to the pancakes in life = "BufferedReader, InputStream in the source code

2.8. Flyweight mode: optimize resource allocation and reduce repetitive waste=》 The purpose is to share resource pool=》National Social Security Network=》String, Integer, ObjectPool

2.9. Combination mode: People together are called gangs, and hearts together are called teams = "The purpose is to unify the whole and the individual, the folder is composed of files, and the files will disappear if the folder is deleted = "Organizational structure tree in life = 》HashMap, SqlNode

2.10. Adapter mode: The best for you is the best = "The purpose is compatible conversion = "Power adapter in life = "AdvisorAdapter\HandlerAdapter in the source code

2.11. Bridge mode: Convention is better than configuration = "Abstract from reality connection =" Purpose does not allow inheritance = "Life case bridge =" DriverManager in the source code

Guess you like

Origin blog.csdn.net/qq_28500837/article/details/112845462