2019.9.01 five basic principles

Single responsibility principle SRP (Single Responsibility Principle)
refers to a class of single function, not all-inclusive. As a people, the distribution of work can not be too much, otherwise all day long, although busy, but the efficiency is not high up.

Open Closed Principle OCP (Open-Close Principle) 
a module in scalability should be open in terms of changes should be closed. For example: a network module, only the original server function, and now want to join the client function,
then it should be in the code without modifying the server function of the premise, it is possible to increase the code that implements the client function, which requires early in the design, They should be separated from the server and the client, the public part of the abstract.

Richter substitution principle (the Liskov Substitution Principle LSP) 
sub-class should be able to replace the parent class and appear anywhere in the parent class can appear. For example: the company engage in an annual party, all employees can participate in the drawing, so whether it is new or old staff employees,
regardless of headquarters employees or expatriates, all should be able to participate in the drawing, otherwise the company would discord.

Dependency Inversion Principle (the Dependency Inversion Principle DIP) particular abstract dependent, dependent on the lower layer an upper layer. Suppose B is lower than the module A, B but need to use the function A,
this time, B should not be used directly in the concrete class A: and should define an abstract interface consisting of B, A to achieve this by the abstract interface, B using only the abstract interface: this achieves
the object of the dependent inverted, B also lifted dependence on a, which in turn is dependent on the definition of a B abstract interface. Upper module by the lower module is difficult to avoid dependence, if B is also directly dependent on implement A, then it may result in a circular dependency. A common problem is the need to be included when compiling A module directly to cpp file module B, and B is also to be included when compiling cpp file directly to the A's.

Interface separation principles (the Interface Segregation Principle ISP) 
between the modules through the abstract interface isolated, rather than through a specific class of strong coupling together


Demeter
Demeter (Law of Demeter) also called the principle of least knowledge (Least Knowledge Principle abbreviation LKP), that is a subject should have as little understanding of other objects, do not talk to strangers.
English abbreviated as:. LoD Demeter can simply say: talk only to your immediate friends. For OOD facing it, as has been explained in several ways: a software entity should be as little interaction with other entities. Each software unit to other units have only minimal knowledge, and limited to those closely related to the software unit of the unit.

  Demeter intention is to reduce the coupling between classes. Since each class to minimize reliance on other classes, and therefore, is easy to make the system function modules function independently, absent each other (or very few) dependencies.
Law of Demeter does not want the class to directly establish direct contact. If there is need to establish contact, but also hope that through its class to convey friend. Therefore, a consequence of the application may cause the Law of Demeter is this: there are a lot of intermediary class system, classes exists solely for mutual transfer calls between classes - which increases the system to a certain extent the complexity.
Are interested can look at the facade design pattern mode (Facade) and intermediary mode (Mediator), are examples of the application of the Law of Demeter.

 
Category:  Object-Oriented

Single responsibility principle SRP (Single Responsibility Principle)
refers to a class of single function, not all-inclusive. As a people, the distribution of work can not be too much, otherwise all day long, although busy, but the efficiency is not high up.

Open Closed Principle OCP (Open-Close Principle) 
a module in scalability should be open in terms of changes should be closed. For example: a network module, only the original server function, and now want to join the client function,
then it should be in the code without modifying the server function of the premise, it is possible to increase the code that implements the client function, which requires early in the design, They should be separated from the server and the client, the public part of the abstract.

Richter substitution principle (the Liskov Substitution Principle LSP) 
sub-class should be able to replace the parent class and appear anywhere in the parent class can appear. For example: the company engage in an annual party, all employees can participate in the drawing, so whether it is new or old staff employees,
regardless of headquarters employees or expatriates, all should be able to participate in the drawing, otherwise the company would discord.

Dependency Inversion Principle (the Dependency Inversion Principle DIP) particular abstract dependent, dependent on the lower layer an upper layer. Suppose B is lower than the module A, B but need to use the function A,
this time, B should not be used directly in the concrete class A: and should define an abstract interface consisting of B, A to achieve this by the abstract interface, B using only the abstract interface: this achieves
the object of the dependent inverted, B also lifted dependence on a, which in turn is dependent on the definition of a B abstract interface. Upper module by the lower module is difficult to avoid dependence, if B is also directly dependent on implement A, then it may result in a circular dependency. A common problem is the need to be included when compiling A module directly to cpp file module B, and B is also to be included when compiling cpp file directly to the A's.

Interface separation principles (the Interface Segregation Principle ISP) 
between the modules through the abstract interface isolated, rather than through a specific class of strong coupling together


Demeter
Demeter (Law of Demeter) also called the principle of least knowledge (Least Knowledge Principle abbreviation LKP), that is a subject should have as little understanding of other objects, do not talk to strangers.
English abbreviated as:. LoD Demeter can simply say: talk only to your immediate friends. For OOD facing it, as has been explained in several ways: a software entity should be as little interaction with other entities. Each software unit to other units have only minimal knowledge, and limited to those closely related to the software unit of the unit.

  Demeter intention is to reduce the coupling between classes. Since each class to minimize reliance on other classes, and therefore, is easy to make the system function modules function independently, absent each other (or very few) dependencies.
Law of Demeter does not want the class to directly establish direct contact. If there is need to establish contact, but also hope that through its class to convey friend. Therefore, a consequence of the application may cause the Law of Demeter is this: there are a lot of intermediary class system, classes exists solely for mutual transfer calls between classes - which increases the system to a certain extent the complexity.
Are interested can look at the facade design pattern mode (Facade) and intermediary mode (Mediator), are examples of the application of the Law of Demeter.

Guess you like

Origin www.cnblogs.com/LiTZen/p/11444259.html