The below article is referenced from http://mmiika.wordpress.com/oo-design-principles/
S.O.L.I.D. Class Design Principles
Collected by Robert C. Martin for his book “Applying Principles and Patterns”,
Single Responsibility Principle (SRP)
A class should have only one reason to change. For example, 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.
- http://davidhayden.com/blog/dave/archive/2005/05/29/1066.aspx
- http://c2.com/cgi/wiki?SingleResponsibilityPrinciple
- Head First Design patterns page 185, 336, 339, 367
- http://msdn.microsoft.com/en-us/magazine/cc546578.aspx
Open/Closed Principle (OCP)
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
- http://davidhayden.com/blog/dave/archive/2005/06/04/1096.aspx
- http://en.wikipedia.org/wiki/Open/closed_principle
- Head First Design patterns page 86-87, 407
- http://c2.com/cgi/wiki?OpenClosedPrinciple
Liskov substitution principle (LSP)
Subtypes must be substitutable for their base types. If class A inherits from class B, then wherever you can use A you should be able to use B. E.g. remember that square is not necessarily a rectangle! When extending: Preconditions cannot be straightened, Postconditions cannot be loosened, visible Invariants cannot be changed (?). Invariants: users depend on this both before and after sending a message. Use a proper set-based inheritance relationship. Not following set semantics is very risky. Subsumption Rule: A reference to a subtype can be used in any context where a reference to a super type is expected. This principle extremely limits what SHOULD be done with the pure extension (inheritance) mechanism. Do not follow at your own risk.
- http://davidhayden.com/blog/dave/archive/2005/06/10/1226.aspx
- Agile Principles and Patterns page ?
- http://c2.com/cgi/wiki?LiskovSubstitutionPrinciple
- http://en.wikipedia.org/wiki/Liskov_substitution_principle
- http://javaboutique.internet.com/tutorials/JavaOO/
Interface Segregation Principle (ISP)
The dependency of one class to another one should depend on the smallest possible interface.
- http://davidhayden.com/blog/dave/archive/2005/06/15/1482.aspx
- http://c2.com/cgi/wiki?InterfaceSegregationPrinciple
- http://www.google.com/search?q=interface+segration+principle
- http://doodleproject.sourceforge.net/articles/2001/interfaceSegregationPrinciple.html
Dependency Inversion Principle (DIP)
Depend upon abstractions (interfaces), not upon concrete classes.
No comments:
Post a Comment