6 large object-oriented design principles

First, the Dependency Inversion Principle (DIP)
layer module (stabilizer) should not depend on the underlying module (variation), both should depend on abstractions (stable)
Abstract (stabilizer) should not depend on the implementation details (variation), the implementation details should abstract dependent on (steady)
condition: a stable class a, class labile B, C, abstract or interface D (stable)

Let A depends on B / C is caused by dependency inversion, because it is dependent on stable unstable

The right to be let A, B, C depend on the interface D. Stability depend on stable, unstable dependence stable.

Dependency Inversion Principle is actually oriented programming interface

 

Second, the opening and closing principle (OCP)
type modules should be extensible, but can not be modified
simple factory pattern violates the principle of opening and closing, so that the design pattern 23 is not inside. Factory method and abstract factory pattern follows the principle of opening and closing.

Opening and closing function expansion principle is open, closed internal code changes

 

Third, the single principle (SRP)
reason for a class should have only one cause it change
the direction of change implies the responsibility of the class of
a class is only responsible for one thing, a duty (to create and use separate objects, but also in line with the principles of the single)

 

 

Fourth, the substitution principle in formula (Liskov) (LSP)
subclass must be able to replace their base class (IS-A)
Do not change the parent class of the original function, or is a combination rather than inherited
subclass can extend the parent class function, but do not change the original function of the parent class

 

V. Interface Segregation Principle (ISP)
design interface functions fine-grained as possible, the smallest functional unit
should not be forced to clients without their method relies
interfaces should be small and complete
design of the interface features fine-grained as possible, the smallest functional unit

 

Sixth, Dimitri principle (LoD)
also known as the principle of least knowledge, that an object should be aware of other objects as little as possible, do not talk to strangers
reduce the coupling (internal method, local variable, not to introduce a new category)
---------------------

Guess you like

Origin www.cnblogs.com/lpbk/p/11223274.html