Design mode six principles, Single Responsibility Principle, Open-Closed Principle Liskov Substitution Principle of Demeter Interface Segregation Principle Dependence Inversion Principle, can be written down as SOLID.

 

The single responsibility principle defines: Do not have more than one cause for a class change. Class C has two member functions F1 and F2, which are responsible for P1 and P2. Due to the change of P1, F1 has been modified, and the modification of F1 may cause the failure of F2, which originally ran normally. Responsibility diffusion, responsibility P is divided into responsibilities P1 and P2. Solution: Two classes C1 and C2 correspond to P1 and P2 respectively. DAO (Data storage object) mode, a class corresponding to a database table, four functions corresponding to add and delete check. The most likely reason for the change is that the table structure changes. In this case, additions, deletions, checks and changes need to be modified.

Open closed Principle A software entity should be open for extension and closed for modification. Commonly said: can add interface and modify the implementation of the interface; You cannot delete or modify an interface. Common methods:

Abstraction constrains abstraction. (a) constrain extension through interfaces or abstract classes; B. Use interfaces or abstract classes as far as possible for parameter types and reference objects; C) keep the abstraction level as stable as possible.

Metadata, in plain English, is configuration parameters, which can be obtained from files or databases.

Develop project charter, charter is better than configuration.

Encapsulate changes, such as a possible change into a class.

The rectangle class has two member functions: set length and width; The square derives from the rectangle, overwriting both functions to ensure that the length and width are equal. A function that takes a rectangle and a square and sets its length and width to 4 and 2, respectively, produces a function that takes a rectangle and a square and sets its length and width to 2.

The li substitution principle means that if you replace an object of a base class with one of its subclasses, the program will not produce any errors. A subclass can override only the abstract methods of its parent class, not the non-abstract methods of its parent class, and can add its own methods. When a subclass’s method overrides a parent class’s method, the method’s preconditions (that is, the method’s input/input parameters) are looser than the parent method’s input parameters. The postcondition of a method (that is, the output/return value of the method) is reversed. Demeter’s Rule Demeter’s Rule is defined as: Only talk to your immediate friends. Direct friends: classes in member variables, input and output parameters of methods, and return values. Indirect friends: local variables, member variables of direct friends. Common principles:

Making a class immutable is a priority. Minimize access to a class. Use Serializable with caution. Minimize the access rights of members. The interface isolation principle defines that a client should not rely on interfaces it does not need; The dependency of one class on another should be based on the smallest interface. Counterexample: Different users use one large interface. Note:

Keep interfaces small, but limited. Small interfaces increase flexibility, and more interfaces increase complexity. Only the methods it needs are exposed to the calling class, and the methods it doesn’t need are hidden. Interfaces can accomplish the most with the fewest methods programming toward interfaces – Dependency Inversion Principle High-level modules should not depend on low-level modules, both should depend on their abstractions not on details details should depend on abstractions