SlideShare uma empresa Scribd logo
1 de 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/

Mais conteúdo relacionado

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"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
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Último (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"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...
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

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.