Class Design Principles - Michael Kennedy @ Code Camp


Michael Kennedy's session in SoCal codecamp, "Five Fundamental Object Oriented Design Principles for Agile Development" discussed the following postulates of class design mentioned in several Fowler’s Refactoring with examples.


 



  • Single Responsibility Principle (SRP)


    • Classes should not have more than one focus of responsibility.

  • Open/Closed Principle (OCP)


    • Class should be open for extending, but closed for modification.

  • Liskov Substitution Principle (Design by Contract)


    • Subtypes must be substitutable for their base types.

  • Dependency Inversion Principle (DIP)


    • Don't have high-level code directly call/inherit from library but use interfaces.

  • Interface Segregation Principle


    • Clients should not be forced to depend on methods (inherit from or implement) they don't use.


These are just one line summaries. Details can be found on links specified below. I found Barbara Liskov’s “Liskov Substitution Principle” most interesting as it has transitioned from this:


 


Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T.[1]


 


To this


 


Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it [2]


 


To this


 


In class hierarchies, it should be possible to treat a specialized object as if it were a base class object. [3]


 


 


Refactoring: Improving the Design of Existing Code by Martin Fowler, et al


Agile Software Development, Principles, Patterns, and Practices by Robert C. Martin


Principles of Object-Oriented Design


Class Design Principles


Design Patterns


 

Share