SlideShare a Scribd company logo
Object Calisthenics

CODING DOJO
Object Calisthenics Refactoring Dojo
Coding Dojo
• Working in pairs
• TDD (Red, Green, Refactor)
• Doing something you can’t comfortably do
  (yet)
• Slowly 
Format
•   45 minute session
•   Lunch
•   45 minute session
•   Retrospective
The Problem
The Rules…
One level of indentation per method
class 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();
    }
}
One level of indentation per method
class Board {
...

    String board() {
      StringBuffer buf = new StringBuffer();
      collectRows(buf);
      return buf.toString();
    }
}
Don’t use the ELSE keyword
if (status == DONE) {
    doSomething();
} else {
  …

                       Think of
                    polymorphism,
                     Null objects
Wrap all primitives and Strings
public void addHours(int hours);
public void add(HourDuration hours);



currentTime.addHours(2);
                         vs.
HourDuration twoHours = new HourDuration (2);
currentTime.add(twoHours);
First class collections
Any class that contains a collection should
contain no other member variables.
One dot per line
• Law of Demeter

game.getRow(1).countCrosses();
               vs
game.crossesForRow(1);
Don’t abbreviate
• Why do we abbreviate in the first place?
  – Repetition?
  – Names too long?
  – Duplication of context?
Keep all entities small
• No classes over 50 lines
• No packages over 10 files (should be easy)
No classes with more than two
           instance variables
class 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;
                       }
No classes with more than two
           instance variables
class 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;
                       }
No getters/setters/properties
The Rules!
1. One level of indentation per method
2. Don’t use the ELSE keyword
3. Wrap all primitives and Strings
4. First class collections
5. One dot per line
6. Don’t abbreviate
7. Keep all entities small
8. No classes with more than two instance
variables
9. No getters/setters/properties
Object Calisthenics Refactoring Dojo
Credits
• Cat
http://www.funnyjunk.com/funny_pictures/189
828/Calisthenics/
• Kid
http://www.kidsguideperth.com.au/byford-
calisthenics/

More Related Content

PPT
10 - OOP - Inheritance (b)
PPT
7 - OOP - OO Concepts
PPT
PDF
Scala - en bedre Java?
PDF
Scala for Java Developers - Intro
PDF
C h 04 oop_inheritance
PPTX
Cleaning Code - Tools and Techniques for Large Legacy Projects
PPTX
Long Life Software
10 - OOP - Inheritance (b)
7 - OOP - OO Concepts
Scala - en bedre Java?
Scala for Java Developers - Intro
C h 04 oop_inheritance
Cleaning Code - Tools and Techniques for Large Legacy Projects
Long Life Software

Viewers also liked (7)

PPTX
Metricide
PDF
Unit Testing Legacy C
PDF
C++ for Marine Streamer Positioning and Navigation - ACCU 2011
PDF
Ruby everywhere
PPTX
Improve collaboration and confidence with Consumer-driven contracts
PDF
Pipeline conference 2017 - Breaking down your build: architectural patterns f...
PDF
Test driven development in C
Metricide
Unit Testing Legacy C
C++ for Marine Streamer Positioning and Navigation - ACCU 2011
Ruby everywhere
Improve collaboration and confidence with Consumer-driven contracts
Pipeline conference 2017 - Breaking down your build: architectural patterns f...
Test driven development in C
Ad

Similar to Object Calisthenics Refactoring Dojo (20)

PPTX
unit 2 java.pptx
PPT
Lesson2
PPT
Lesson2
PPT
Lesson2
PPTX
Introduction to Java Strings, By Kavita Ganesan
PPTX
Introduction to the Ruby Object Model
PPTX
DOC-20240812-WA0000 array string and.pptx
PPT
14 Defining classes
PDF
Lezione03
PDF
Lezione03
PDF
Lec 8 03_sept [compatibility mode]
PPTX
TKPJava - Teaching Kids Programming - Core Java Langauge Concepts
PDF
F bound-types
PPT
Introduction to Java(basic understanding).ppt
PPTX
Building Java Programas
PDF
ádfasdfasdfasdfasdfasdfsadfsadfasdfasfasdfasdfasdfa
PPTX
Classes, Objects and Method - Object Oriented Programming with Java
PPTX
Object Calisthenics - TDD Milano
PDF
0php 5-online-cheat-sheet-v1-3
unit 2 java.pptx
Lesson2
Lesson2
Lesson2
Introduction to Java Strings, By Kavita Ganesan
Introduction to the Ruby Object Model
DOC-20240812-WA0000 array string and.pptx
14 Defining classes
Lezione03
Lezione03
Lec 8 03_sept [compatibility mode]
TKPJava - Teaching Kids Programming - Core Java Langauge Concepts
F bound-types
Introduction to Java(basic understanding).ppt
Building Java Programas
ádfasdfasdfasdfasdfasdfsadfsadfasdfasfasdfasdfasdfa
Classes, Objects and Method - Object Oriented Programming with Java
Object Calisthenics - TDD Milano
0php 5-online-cheat-sheet-v1-3
Ad

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
Teaching material agriculture food technology
PDF
cuic standard and advanced reporting.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation_ Review paper, used for researhc scholars
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Understanding_Digital_Forensics_Presentation.pptx
Teaching material agriculture food technology
cuic standard and advanced reporting.pdf
Empathic Computing: Creating Shared Understanding
MIND Revenue Release Quarter 2 2025 Press Release
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction

Object Calisthenics Refactoring Dojo

  • 3. Coding Dojo • Working in pairs • TDD (Red, Green, Refactor) • Doing something you can’t comfortably do (yet) • Slowly 
  • 4. Format • 45 minute session • Lunch • 45 minute session • Retrospective
  • 7. One level of indentation per method class 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(); } }
  • 8. One level of indentation per method class Board { ... String board() { StringBuffer buf = new StringBuffer(); collectRows(buf); return buf.toString(); } }
  • 9. Don’t use the ELSE keyword if (status == DONE) { doSomething(); } else { … Think of polymorphism, Null objects
  • 10. Wrap all primitives and Strings public void addHours(int hours); public void add(HourDuration hours); currentTime.addHours(2); vs. HourDuration twoHours = new HourDuration (2); currentTime.add(twoHours);
  • 11. First class collections Any class that contains a collection should contain no other member variables.
  • 12. One dot per line • Law of Demeter game.getRow(1).countCrosses(); vs game.crossesForRow(1);
  • 13. Don’t abbreviate • Why do we abbreviate in the first place? – Repetition? – Names too long? – Duplication of context?
  • 14. Keep all entities small • No classes over 50 lines • No packages over 10 files (should be easy)
  • 15. No classes with more than two instance variables class 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. No classes with more than two instance variables class 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; }
  • 18. The Rules! 1. One level of indentation per method 2. Don’t use the ELSE keyword 3. Wrap all primitives and Strings 4. First class collections 5. One dot per line 6. Don’t abbreviate 7. Keep all entities small 8. No classes with more than two instance variables 9. No getters/setters/properties