Seven major design principles:
1. Single RESPONSIBILITY PRINCIPLE: one class is responsible for one responsibility.
2, the Richter replacement principle "LISKOV SUBSTITUTION PRINCIPLE": Inherited and derived rules. (Subclass replaceable Parent Class)
3, relying on the reversal principle "dependence inversion PRINCIPLE": high-level modules should not rely on the lower layer module, both should rely on its abstraction; abstraction should not depend on detail; detail should depend on abstraction. That is, for interface programming, do not program for implementation.
4, the interface isolation principle "INTERFACE segregation PRINCIPLE": Establish a single interface, do not set up a huge bloated interface, as far as possible to refine the interface, the interface of the method as little as possible.
5. Dimitri law "low of DEMETER": Cohesion Poly-–high cohesion lo coupling
6. Open Close PRINCIPLE: A software entity such as classes, modules, and functions should be open to extensions and closed for modification.
7, combination/aggregation multiplexing principle "composition/aggregation reuse Principle (CARP)": Try to use combination and aggregation less use of inherited relationships to achieve the principle of reuse.
24 Different design modes:
First, the creation mode
1. Abstract Factory Pattern: Provides an interface for creating a family of related or dependent objects without specifying a specific class.
2. Builder pattern: Use the builder pattern to encapsulate a product's construction process and allow for the steps to be constructed. Separating the construction of a complex object from its representation allows the same build process to create different representations.
3. Factory mode (factory method pattern): Defines an interface for creating objects, but subclasses decide which class to instantiate. The factory method defers the instantiation of the class to the subclass.
4. Prototype mode (prototype pattern): Use prototype mode when creating an instance of a given class is expensive or complex.
5. Singleton mode (Singleton pattern): Ensures that a class has only one instance and provides a global access point.
6. Multiple patterns (multition pattern): combine two or more patterns in a solution to solve general or recurring problems.
Second, structural type mode
1. Adapter mode (Adapter pattern): Converts the interface of a class into another interface that the customer expects. Adapters allow classes that are incompatible with the original interface to work together. Object adapters use combinations, and class adapters use multiple inheritance.
2, Bridging mode (bridge pattern): The use of bridging mode allows them to change independently by placing the implementation and abstraction in two different class hierarchies.
3. Combination mode (composite pattern): Allows you to combine objects into a tree structure to represent a "whole/part" hierarchy. The combination enables the customer to handle individual objects and object combinations in a consistent manner.
4, Decorator mode (decorator pattern): Dynamically attaches responsibility to the object, to extend the functionality, the adorner provides a more flexible alternative than inheritance.
5. Appearance mode (facade pattern): Provides a unified interface for accessing a group of interfaces in a subsystem. The appearance defines a high-level interface that makes the subsystem easier to use.
6. Hengyuan mode (Flyweight pattern): If you want an instance of a class to be used to provide many "virtual instances", use the fly volume pattern.
7. Proxy pattern: Provides an alias or placeholder for another object to control access to the object.
Iii. Behavioral Patterns
1, responsibility Chain mode (Chain of responsibility Pattern): Through the chain of responsibility model, you can create an object chain for a request. Each object sequentially examines the request and processes it, or passes it to the next object in the chain.
2. Command pattern: The request is closed to objects so that different requests, queues, or logs are used to parameterize other objects. The command mode also supports the revocable operation.
3. Interpreter mode (interpreter pattern): Use the Interpreter mode to create an interpreter for the language.
4. Iterator mode (iterator pattern): Provides a way to sequentially access individual elements in an aggregated object without exposing their internal representations.
5. Intermediary mode (mediator pattern): Use the mediator mode to centralize the complex communication and control between related objects.
6. Memo Mode (Memento pattern): When you need to return an object to its previous state (for example, your user requests "undo"), you use Memo mode.
7. Observer pattern (Observer pattern): Defines a one-to-many dependency between objects, so that when an object changes state, objects that depend on it are notified and updated automatically.
8. State pattern: Allows an object to change its behavior when the internal state changes, and the object looks as if it had changed its class.
9, the Strategy mode (strategy pattern): Defines the algorithm family, respectively closed up, so that they can replace each other, this mode allows the algorithm to change independently of the customer using the algorithm.
10. Template Method Pattern: Defines the skeleton of an algorithm in one method, and delays some steps into subclasses. The template method allows subclasses to redefine some of the steps in the algorithm without changing the structure of the algorithm.
11. Visitor Mode (visitor pattern): Use the visitor pattern when you want to add new capabilities to a combination of objects, and if the encapsulation is not important.
Seven principles of Python, 24 design Patterns