套用各种DP写一个系统,跑起来了,但后来发现真有变化来临的时候想扩展还得大规模改动甚至重写,这就是传说中的DP乱套了,达不到效果反而徒增工作量,内心惭愧,于是细读OO大师的设计信条,才慢慢明晓DP要怎么样实作才能真正达到效果,记下六大原则原文,肃清乱套之风,以作警戒。
Single Responsibility Principle: There should never be more than one reason for a class to change.
Open Closed Principle: Software entities like classes, modules and functions should be open for extension but closed for modifications.
Liskov Substitution Principle: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.
Law of Demeter: Least Knowledge Principle. Only talk to your immedate friends.
Interface Segregation Principle: Clients should not be forced to depend upon interfaces that they don't use. The dependency of one class to another one should depend on the smallest possible interface.
Dependence Inversion Principle: High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.
Single Responsibility Principle: There should never be more than one reason for a class to change.
Open Closed Principle: Software entities like classes, modules and functions should be open for extension but closed for modifications.
Liskov Substitution Principle: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.
Law of Demeter: Least Knowledge Principle. Only talk to your immedate friends.
Interface Segregation Principle: Clients should not be forced to depend upon interfaces that they don't use. The dependency of one class to another one should depend on the smallest possible interface.
Dependence Inversion Principle: High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.