slug | id | title | date | comments | tags | description | references | |
---|---|---|---|---|---|---|---|---|
12-solid-design-principles |
12-solid-design-principles |
SOLID Design Principles |
2018-08-13 18:07 |
true |
|
SOLID is an acronym of design principles that help software engineers write solid code. S is for single responsibility principle, O for open/closed principle, L for Liskov’s substitution principle, I for interface segregation principle and D for dependency inversion principle. |
SOLID is an acronym of design principles that help software engineers write solid code within a project.
-
S - Single Responsibility Principle. A module should be responsible to one, and only one, actor. a module is just a cohesive set of functions and data structures.
-
O - Open/Closed Principle. A software artifact should be open for extension but closed for modification.
-
L - Liskov’s Substitution Principle. Simplify code with interface and implementation, generics, sub-classing, and duck-typing for inheritance.
-
I - Interface Segregation Principle. Segregate the monolithic interface into smaller ones to decouple modules.
-
D - Dependency Inversion Principle. The source code dependencies are inverted against the flow of control. most visible organizing principle in our architecture diagrams.
- Things should be stable concrete, Or stale abstract, not ==concrete and volatile.==
- So use ==abstract factory== to create volatile concrete objects (manage undesirable dependency.) 产生 interface 的 interface
- DIP violations cannot be entirely removed. Most systems will contain at least one such concrete component — this component is often called main.