There are five principles of class design (aka SOLID)

The Single Responsibility Principle(SRP):
Each responsibility should be a separate class, because each responsibility is an axis of change.
A class should have one, and only one, reason to change.
If a change to the business rules causes a class to change, then a change to the database schema, GUI, report format, or any other segment of the system should not force that class to change.


Dependency Inversion Principle(DIP):
A. High level modules should not depend upon low level modules. Both should depend upon abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions.


Interface Segregation Principle(ISP):
The dependency of one class to another one should depend on the smallest possible interface.


Liskov Substitution Principle(LSP):
What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T."


Open Closed Principle(OCP):

Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.


參考:
http://c2.com/cgi/wiki?PrinciplesOfObjectOrientedDesign

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章