Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
work:clean_code_notes [13 years ago - 2012/12/06 19:34] – created aogailwork:clean_code_notes [13 years ago - 2013/01/04 21:54] (current) – [Clean Code notes] aogail
Line 1: Line 1:
 ====== Clean Code notes ====== ====== Clean Code notes ======
 +
 +===== Liskov substitution principle =====
 +
 +==== What is a type ====
 +
 +It is a bag of operations
 +
 +==== Subtypes ====
 +
 +A subtype is a type that may be used as another type.
 +
 +==== Refused bequest ====
 +
 +This occurs when a subtype does something unexpected from the point of view of the user of the super type. 
 +
 +  * does not implement method
 +  * method does something unexpected
 +  * etc.
 +
 +Every refused bequest/LSP violation is a latent open/closed principle violation. 
 +
 +==== Representative rule ====
 +
 +Representatives of things do not share the relationships of the things they represent. So, while geometrically a square is a rectangle, the class that represents a square is not a subtype of the class that represents a rectangle. 
 +
 +
  
 ===== Single responsibility principle ===== ===== Single responsibility principle =====
Line 9: Line 35:
     * The actor is the single source of change for the functions in a responsibility     * The actor is the single source of change for the functions in a responsibility
   * Primary and secondary value of software   * Primary and secondary value of software
-    * Primary: can be changed easily+    * Primary: can be changed easily, so that it can  continue to meet changing needs of customer
     * Secondary: meets current needs of current customer     * Secondary: meets current needs of current customer
   * Primary value is achieved in the process of assigning functions to modules   * Primary value is achieved in the process of assigning functions to modules
Line 45: Line 71:
         * interface: supports sesifner         * interface: supports sesifner
       * see mastermind example       * see mastermind example
-      + 
 + 
 +===== Open closed principle ===== 
 + 
 +  modules should be open for extension, closed for modification 
 +  * changing behavior of module should not require changing module's source 
 +  * problem: need crystal ball to anticipate future changes in order to design to protect yourself using open closed 
 +  * solutions: big design up front, agile design 
 +  * agile: do simplest thing now, refactor and abstract once customers ask for modifications 
 +    * get initial builds in front of customers. Customers will immediately request changes. Developers should change architecture to account for these changes, then refactor to implement new abstractions. 
 +    * each iteration should result in more code that conforms to open/closed 
 +    *  
 + 
 +