SlideShare a Scribd company logo
1 of 20
Object Calisthenics

CODING 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
Credits
• Cat
http://www.funnyjunk.com/funny_pictures/189
828/Calisthenics/
• Kid
http://www.kidsguideperth.com.au/byford-
calisthenics/

More Related Content

Viewers also liked

Unit Testing Legacy C
Unit Testing Legacy CUnit Testing Legacy C
Unit Testing Legacy CMike Long
 
C++ for Marine Streamer Positioning and Navigation - ACCU 2011
C++ for Marine Streamer Positioning and Navigation - ACCU 2011C++ for Marine Streamer Positioning and Navigation - ACCU 2011
C++ for Marine Streamer Positioning and Navigation - ACCU 2011Mike Long
 
Improve collaboration and confidence with Consumer-driven contracts
Improve collaboration and confidence with Consumer-driven contractsImprove collaboration and confidence with Consumer-driven contracts
Improve collaboration and confidence with Consumer-driven contractsPierre Vincent
 
Pipeline conference 2017 - Breaking down your build: architectural patterns f...
Pipeline conference 2017 - Breaking down your build: architectural patterns f...Pipeline conference 2017 - Breaking down your build: architectural patterns f...
Pipeline conference 2017 - Breaking down your build: architectural patterns f...Abraham Marin-Perez
 
Test driven development in C
Test driven development in CTest driven development in C
Test driven development in CAmritayan Nayak
 

Viewers also liked (7)

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

Similar to Object Calisthenics Refactoring Dojo

Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanKavita Ganesan
 
Introduction to the Ruby Object Model
Introduction to the Ruby Object ModelIntroduction to the Ruby Object Model
Introduction to the Ruby Object ModelMiki Shiran
 
14 Defining classes
14 Defining classes14 Defining classes
14 Defining classesmaznabili
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
TKPJava - Teaching Kids Programming - Core Java Langauge Concepts
TKPJava - Teaching Kids Programming - Core Java Langauge ConceptsTKPJava - Teaching Kids Programming - Core Java Langauge Concepts
TKPJava - Teaching Kids Programming - Core Java Langauge ConceptsLynn Langit
 
Building Java Programas
Building Java ProgramasBuilding Java Programas
Building Java Programasssuser4df5ef
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
 
0php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-30php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-3Fafah Ranaivo
 

Similar to Object Calisthenics Refactoring Dojo (20)

unit 2 java.pptx
unit 2 java.pptxunit 2 java.pptx
unit 2 java.pptx
 
Lesson2
Lesson2Lesson2
Lesson2
 
Lesson2
Lesson2Lesson2
Lesson2
 
Lesson2
Lesson2Lesson2
Lesson2
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
 
Introduction to the Ruby Object Model
Introduction to the Ruby Object ModelIntroduction to the Ruby Object Model
Introduction to the Ruby Object Model
 
Cis166 Final Review C#
Cis166 Final Review C#Cis166 Final Review C#
Cis166 Final Review C#
 
14 Defining classes
14 Defining classes14 Defining classes
14 Defining classes
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
TKPJava - Teaching Kids Programming - Core Java Langauge Concepts
TKPJava - Teaching Kids Programming - Core Java Langauge ConceptsTKPJava - Teaching Kids Programming - Core Java Langauge Concepts
TKPJava - Teaching Kids Programming - Core Java Langauge Concepts
 
F bound-types
F bound-typesF bound-types
F bound-types
 
Building Java Programas
Building Java ProgramasBuilding Java Programas
Building Java Programas
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
Object Calisthenics - TDD Milano
Object Calisthenics - TDD MilanoObject Calisthenics - TDD Milano
Object Calisthenics - TDD Milano
 
0php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-30php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-3
 
E2
E2E2
E2
 
Java
Java Java
Java
 
Coding Guidelines in CPP
Coding Guidelines in CPPCoding Guidelines in CPP
Coding Guidelines in CPP
 

Recently uploaded

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Object Calisthenics Refactoring Dojo

  • 2.
  • 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
  • 19.