Object Calisthenics Refactoring Dojo

4,826 views

Published on

Introductory slides for an Object Calisthenics Refactoring Dojo

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,826
On SlideShare
0
From Embeds
0
Number of Embeds
3,040
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Object Calisthenics Refactoring Dojo

  1. 1. Object CalisthenicsCODING DOJO
  2. 2. Coding Dojo• Working in pairs• TDD (Red, Green, Refactor)• Doing something you can’t comfortably do (yet)• Slowly 
  3. 3. Format• 45 minute session• Lunch• 45 minute session• Retrospective
  4. 4. The Problem
  5. 5. The Rules…
  6. 6. One level of indentation per methodclass Board {... String board() { StringBuffer buf = new StringBuffer(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) buf.append(data[i][j]); buf.append(“n”); } return buf.toString(); }}
  7. 7. One level of indentation per methodclass Board {... String board() { StringBuffer buf = new StringBuffer(); collectRows(buf); return buf.toString(); }}
  8. 8. Don’t use the ELSE keywordif (status == DONE) { doSomething();} else { … Think of polymorphism, Null objects
  9. 9. Wrap all primitives and Stringspublic void addHours(int hours);public void add(HourDuration hours);currentTime.addHours(2); vs.HourDuration twoHours = new HourDuration (2);currentTime.add(twoHours);
  10. 10. First class collectionsAny class that contains a collection shouldcontain no other member variables.
  11. 11. One dot per line• Law of Demetergame.getRow(1).countCrosses(); vsgame.crossesForRow(1);
  12. 12. Don’t abbreviate• Why do we abbreviate in the first place? – Repetition? – Names too long? – Duplication of context?
  13. 13. Keep all entities small• No classes over 50 lines• No packages over 10 files (should be easy)
  14. 14. No classes with more than two instance variablesclass Name { class Name { String first; Surname family; String middle; GivenNames given; String last; }} class Surname {would be decomposed String family;into two classes }thus=> class GivenNames { List<String> names; }
  15. 15. No classes with more than two instance variablesclass Name { class Name { String first; Surname family; String middle; GivenNames given; String last; }} class Surname {would be decomposed String family;into two classes }thus=> class GivenNames { List<String> names; }
  16. 16. No getters/setters/properties
  17. 17. The Rules!1. One level of indentation per method2. Don’t use the ELSE keyword3. Wrap all primitives and Strings4. First class collections5. One dot per line6. Don’t abbreviate7. Keep all entities small8. No classes with more than two instancevariables9. No getters/setters/properties
  18. 18. Credits• Cathttp://www.funnyjunk.com/funny_pictures/189828/Calisthenics/• Kidhttp://www.kidsguideperth.com.au/byford-calisthenics/

×