SlideShare a Scribd company logo

Object Calisthenics - TDD Milano

Object Calisthenics workshop at #TDDMilano meetup https://www.meetup.com/it-IT/TDD-Milano/ Thank to https://www.mikamai.com/ for the hospitality

1 of 31
Download to read offline
Object
Calisthenics
#TDDMilano
Ferdinando Santacroce
@jesuswasrasta
“
2
The word calisthenics comes from
the ancient Greek words kalòs
(καλός), beauty, and sthénos
(σθένος), strength.
@jesuswasrasta #TDDMilano
“
3
So, here’s an exercise that can help you to
internalize principles of good object-oriented
design and actually use them in real life.
Jeff Bay
@jesuswasrasta #TDDMilanobit.ly/ObjectCalisthenics
4
class Board {
public String print() {
StringBuilder buffer = new StringBuilder();
//Level 0
for (int i = 0; i < 10; i++) {
//Level 1: OK
for (int j = 0; j < 10; j++) {
//Level 2: NOT ALLOWED!
buffer.append(data[i][j]);
}
buffer.append("n");
}
return buffer.toString();
}
}
1. Only one level of indentation per method
@jesuswasrasta #TDDMilano
5
if(status==Status.DONE){
doSomething();
} else {//ELSE NOT ALLOWED!
doSomethingElse();
}
2. Don’t use ELSE keyword
@jesuswasrasta #TDDMilano
6
3. Wrap all primitives and strings
class ZipCode{
String regex = "^[0-9]{5}(?:-[0-
9]{4})?$";
Pattern pattern = Pattern.compile(regex);
String value;
public ZipCode(String value) {
this.value = value;
}
public boolean isWellFormed(){
return pattern.matcher(value).matches();
}
}
//Don't use primitives!
String regex = "^[0-9]{5}(?:-[0-9]{4})?$";
Pattern pattern = Pattern.compile(regex);
String zip = "12345";
if (pattern.matcher(value).matches()){
//...
}
//Use objects, we are doing OOP, after
all..
ZipCode zipCode = new ZipCode("12345");
if(zipCode.isWellFormed()){
//...
}
@jesuswasrasta #TDDMilano

Recommended

5 little clojure functions
5 little clojure functions5 little clojure functions
5 little clojure functionsDiego Pacheco
 
Breaking and bending Flexbox on the quest for the holy CSS grail: masonry lay...
Breaking and bending Flexbox on the quest for the holy CSS grail: masonry lay...Breaking and bending Flexbox on the quest for the holy CSS grail: masonry lay...
Breaking and bending Flexbox on the quest for the holy CSS grail: masonry lay...Shift Conference
 
Object Calisthenics - Agile Venture Prato 2018
Object Calisthenics - Agile Venture Prato 2018Object Calisthenics - Agile Venture Prato 2018
Object Calisthenics - Agile Venture Prato 2018Ferdinando Santacroce
 
Jeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean CodeJeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean CodeAwesome Ars Academia
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfjillisacebi75827
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.pptMikeAdva
 

More Related Content

Similar to Object Calisthenics - TDD Milano

The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2Coursetro Com
 
Effective Java with Groovy
Effective Java with GroovyEffective Java with Groovy
Effective Java with GroovyNaresha K
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...Functional Thursday
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsMarcin Grzejszczak
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementShiny Zhu
 
How Good of a Java Developer are You?
How Good of a Java Developer are You?How Good of a Java Developer are You?
How Good of a Java Developer are You?Sherif Koussa
 
AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)James Titcumb
 
Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Sam Livingston-Gray
 
Java beginners meetup: Introduction to class and application design
Java beginners meetup: Introduction to class and application designJava beginners meetup: Introduction to class and application design
Java beginners meetup: Introduction to class and application designPatrick Kostjens
 
Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020Alan Richardson
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Brian Hogan
 
Chapter 8 Polymorphism
Chapter 8 PolymorphismChapter 8 Polymorphism
Chapter 8 PolymorphismOUM SAOKOSAL
 

Similar to Object Calisthenics - TDD Milano (20)

Clean code
Clean codeClean code
Clean code
 
The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2
 
Design Patterns: Back to Basics
Design Patterns: Back to BasicsDesign Patterns: Back to Basics
Design Patterns: Back to Basics
 
Effective Java with Groovy
Effective Java with GroovyEffective Java with Groovy
Effective Java with Groovy
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory Management
 
14 Defining Classes
14 Defining Classes14 Defining Classes
14 Defining Classes
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
How Good of a Java Developer are You?
How Good of a Java Developer are You?How Good of a Java Developer are You?
How Good of a Java Developer are You?
 
AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)
 
Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Java beginners meetup: Introduction to class and application design
Java beginners meetup: Introduction to class and application designJava beginners meetup: Introduction to class and application design
Java beginners meetup: Introduction to class and application design
 
Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020Automating Tactically vs Strategically SauceCon 2020
Automating Tactically vs Strategically SauceCon 2020
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7
 
Chapter 8 Polymorphism
Chapter 8 PolymorphismChapter 8 Polymorphism
Chapter 8 Polymorphism
 
Clean Code
Clean CodeClean Code
Clean Code
 

More from Ferdinando Santacroce

More from Ferdinando Santacroce (8)

Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Growing Teams - Agile Venture Milano - #avmi2020
Growing Teams - Agile Venture Milano - #avmi2020Growing Teams - Agile Venture Milano - #avmi2020
Growing Teams - Agile Venture Milano - #avmi2020
 
Testare l'intestabile - Italian Agile Days 2019 #IAD19
Testare l'intestabile - Italian Agile Days 2019 #IAD19Testare l'intestabile - Italian Agile Days 2019 #IAD19
Testare l'intestabile - Italian Agile Days 2019 #IAD19
 
I'm a mediocre developer
I'm a mediocre developerI'm a mediocre developer
I'm a mediocre developer
 
Working software
Working softwareWorking software
Working software
 
I'm a mediocre developer
I'm a mediocre developerI'm a mediocre developer
I'm a mediocre developer
 
TDD a piccoli passi
TDD a piccoli passiTDD a piccoli passi
TDD a piccoli passi
 
Agile versioning with Git
Agile versioning with GitAgile versioning with Git
Agile versioning with Git
 

Recently uploaded

Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...confluent
 
Sql server types of joins with example.pptx
Sql server types of joins with example.pptxSql server types of joins with example.pptx
Sql server types of joins with example.pptxsameer gaikwad
 
killing camp week 6 problem - maximal matrix.pdf
killing camp week 6 problem - maximal matrix.pdfkilling camp week 6 problem - maximal matrix.pdf
killing camp week 6 problem - maximal matrix.pdfssuser82c38d
 
The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...
The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...
The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...emili denli
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!Anthony Dahanne
 
killingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdfkillingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdfssuser82c38d
 
Software Testing life cycle (STLC) Importance, Phases, Benefits...
Software Testing life cycle (STLC) Importance, Phases, Benefits...Software Testing life cycle (STLC) Importance, Phases, Benefits...
Software Testing life cycle (STLC) Importance, Phases, Benefits...Flexsin
 
Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...
Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...
Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...ISPMAIndia
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsBram Vogelaar
 
sql ppt for students who preparing for sql
sql ppt for students who preparing for sqlsql ppt for students who preparing for sql
sql ppt for students who preparing for sqlbharatjanadharwarud
 
AI Product Management by Abhijit Bendigiri
AI Product Management by Abhijit BendigiriAI Product Management by Abhijit Bendigiri
AI Product Management by Abhijit BendigiriISPMAIndia
 
"Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A...
"Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A..."Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A...
"Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A...ISPMAIndia
 
The Age of AI: Elevating Experiences & Delivering Customer Value!
The Age of AI: Elevating Experiences & Delivering Customer Value!The Age of AI: Elevating Experiences & Delivering Customer Value!
The Age of AI: Elevating Experiences & Delivering Customer Value!ISPMAIndia
 
SPM 2024 – Overview of and benefits of AI in Product Management
SPM 2024 – Overview of and benefits of AI in Product ManagementSPM 2024 – Overview of and benefits of AI in Product Management
SPM 2024 – Overview of and benefits of AI in Product ManagementISPMAIndia
 
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTSi-engage
 
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and FlinkDBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and FlinkTimothy Spann
 
App Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptxApp Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptxPoojitha B
 
P1 Inspection Types in Municity 5 Smartsheet
P1 Inspection Types in Municity 5 SmartsheetP1 Inspection Types in Municity 5 Smartsheet
P1 Inspection Types in Municity 5 SmartsheetMatthewTHawley
 
"Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ...
"Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ..."Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ...
"Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ...ISPMAIndia
 
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)GDSCNiT
 

Recently uploaded (20)

Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
 
Sql server types of joins with example.pptx
Sql server types of joins with example.pptxSql server types of joins with example.pptx
Sql server types of joins with example.pptx
 
killing camp week 6 problem - maximal matrix.pdf
killing camp week 6 problem - maximal matrix.pdfkilling camp week 6 problem - maximal matrix.pdf
killing camp week 6 problem - maximal matrix.pdf
 
The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...
The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...
The Game-Changer_ How Software Development Outsource Can Catapult Your Growth...
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!
 
killingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdfkillingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdf
 
Software Testing life cycle (STLC) Importance, Phases, Benefits...
Software Testing life cycle (STLC) Importance, Phases, Benefits...Software Testing life cycle (STLC) Importance, Phases, Benefits...
Software Testing life cycle (STLC) Importance, Phases, Benefits...
 
Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...
Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...
Product Manager vs Product Owner – Why Do Companies Still Struggle 23 Years A...
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloads
 
sql ppt for students who preparing for sql
sql ppt for students who preparing for sqlsql ppt for students who preparing for sql
sql ppt for students who preparing for sql
 
AI Product Management by Abhijit Bendigiri
AI Product Management by Abhijit BendigiriAI Product Management by Abhijit Bendigiri
AI Product Management by Abhijit Bendigiri
 
"Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A...
"Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A..."Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A...
"Discovery and Delivery through Product IntelliGenAI framework" by Ramkumar A...
 
The Age of AI: Elevating Experiences & Delivering Customer Value!
The Age of AI: Elevating Experiences & Delivering Customer Value!The Age of AI: Elevating Experiences & Delivering Customer Value!
The Age of AI: Elevating Experiences & Delivering Customer Value!
 
SPM 2024 – Overview of and benefits of AI in Product Management
SPM 2024 – Overview of and benefits of AI in Product ManagementSPM 2024 – Overview of and benefits of AI in Product Management
SPM 2024 – Overview of and benefits of AI in Product Management
 
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
 
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and FlinkDBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
 
App Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptxApp Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptx
 
P1 Inspection Types in Municity 5 Smartsheet
P1 Inspection Types in Municity 5 SmartsheetP1 Inspection Types in Municity 5 Smartsheet
P1 Inspection Types in Municity 5 Smartsheet
 
"Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ...
"Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ..."Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ...
"Taking an idea to a Product in Health diagnostics" by Dr. Geetha Manjunath, ...
 
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
 

Object Calisthenics - TDD Milano

  • 2. “ 2 The word calisthenics comes from the ancient Greek words kalòs (καλός), beauty, and sthénos (σθένος), strength. @jesuswasrasta #TDDMilano
  • 3. “ 3 So, here’s an exercise that can help you to internalize principles of good object-oriented design and actually use them in real life. Jeff Bay @jesuswasrasta #TDDMilanobit.ly/ObjectCalisthenics
  • 4. 4 class Board { public String print() { StringBuilder buffer = new StringBuilder(); //Level 0 for (int i = 0; i < 10; i++) { //Level 1: OK for (int j = 0; j < 10; j++) { //Level 2: NOT ALLOWED! buffer.append(data[i][j]); } buffer.append("n"); } return buffer.toString(); } } 1. Only one level of indentation per method @jesuswasrasta #TDDMilano
  • 5. 5 if(status==Status.DONE){ doSomething(); } else {//ELSE NOT ALLOWED! doSomethingElse(); } 2. Don’t use ELSE keyword @jesuswasrasta #TDDMilano
  • 6. 6 3. Wrap all primitives and strings class ZipCode{ String regex = "^[0-9]{5}(?:-[0- 9]{4})?$"; Pattern pattern = Pattern.compile(regex); String value; public ZipCode(String value) { this.value = value; } public boolean isWellFormed(){ return pattern.matcher(value).matches(); } } //Don't use primitives! String regex = "^[0-9]{5}(?:-[0-9]{4})?$"; Pattern pattern = Pattern.compile(regex); String zip = "12345"; if (pattern.matcher(value).matches()){ //... } //Use objects, we are doing OOP, after all.. ZipCode zipCode = new ZipCode("12345"); if(zipCode.isWellFormed()){ //... } @jesuswasrasta #TDDMilano
  • 7. 7 //Don't use collections, directly List<String> players = new ArrayList<>(); String player = "John"; if(!(players.contains(player) || players.size() == 5)){ players.add(player); } 4. First class collections (1) @jesuswasrasta #TDDMilano
  • 8. 8 //Wrap collections in meaningful objects Team team = new Team(); team.add(player); //... class Team { List<String> players = new ArrayList<>(); final int TEAM_SIZE = 5; public void add(String player){ if(players.contains(player)){ throw new DuplicatePlayer("Player " + player + " already present"); } if(players.size() == TEAM_SIZE){ throw new TeamFull("Team full, max " + TEAM_SIZE + " players"); } players.add(player); } 4. First class collections (2) @jesuswasrasta #TDDMilano
  • 9. 9 public void update(){ //Only one dot per line context.getSession().update(); //That doesn't means this... Session session = context.getSession(); session.update(); //But this... context.update(); } 5. One dot per line @jesuswasrasta #TDDMilano
  • 10. 10 //Don't do this String signOcr = "John Doe"; srep(signOcr); //But this String signatureFromOcr = "John Doe"; signReport(signatureFromOcr); 6. Don’t abbreviate @jesuswasrasta #TDDMilano
  • 11. 11 7. Keep all entities small //But small and cohesive ones like these! class Player{ Identity identity; Address address; public Player(Identity identity){ this.identity = identity; } public changeAddress(Address address){ this.address = address; } } //Don’t create this kind of entities... class Player{ String firstName; String lastName; String nickName; String city; String street; String streetNumber; String zipCode; public void setFirstName(String firstName){ this.firstName = firstName; } //... //And so on, tons of getters and setter //... } class Identity{ String firstName; String lastName; String nickName; } class Address{ String city; String street; String streetNumber; String zipCode; } @jesuswasrasta #TDDMilano
  • 12. 12 8. No classes with more than two instance variables //But you have to do this! class Identity{ FamilyName familyName; GivenName givenName; } //So, you can’t do this... class Identity{ String firstName; String lastName; String nickName; } class FamilyName{ String firstName; String lastName; } class GivenName{ String nickName; } @jesuswasrasta #TDDMilano
  • 13. 13 9. No getters/setters/properties //You are not allowed to do this... class Player{ String firstName; //... public String zipCode; public void getFirstName(String firstName){ return this.firstName; } public void setFirstName(String firstName){ this.firstName = firstName; } //And so on... } @jesuswasrasta #TDDMilano
  • 14. 14 @jesuswasrasta #TDDMilano Time to get stronger! Setup Farkle Kata 2 pomodoros Pair programming TDD Debriefing, Q&A
  • 16. 16 @jesuswasrasta #TDDMilano Dice, Turn, Throwing, Player, Score? Too many objects? Did rules conflicted, sometimes? Does it felt weird or uncomfortable, maybe? Debriefing
  • 21. 21 1. Only one level of indentation per method Promotes method cohesiveness Single Responsibility Principle (S.O.L.I.D.) Extract method Extract objects (collaborators) @jesuswasrasta #TDDMilano
  • 22. 22 2. Don’t use ELSE keyword Polymorphism Behavioral Patterns Strategy Pattern (set algorithm at runtime) State Pattern (state machines) @jesuswasrasta #TDDMilano
  • 23. 23 3. Wrap all primitives and strings Primitive Obsession Anti-Pattern: Using primitives to represent domain ideas @jesuswasrasta #TDDMilano
  • 24. 24 4. First class collections Encapsulation: Any class that contains a collection should contain no other member variables Give behaviors related to the collection a home @jesuswasrasta #TDDMilano
  • 25. 25 5. One dot per line Law of Demeter Only talk with your immediate friends, don’t talk to strangers Fluent interfaces allowed @jesuswasrasta #TDDMilano
  • 26. 26 6. Don’t abbreviate Naming “Clean Code” book, Robert C. Martin, Ch. 2 Meaningful, intention-revealing, pronounceable, searchable names Method’s name too long? Maybe it does too many things... @jesuswasrasta #TDDMilano
  • 27. 27 7. Keep all entities small Single Responsibility Principle (again...) Class with 50 l.o.c, methods with 5 The “class that fits in the monitor” rule There’s no black & white, it’s all about trade-offs @jesuswasrasta #TDDMilano
  • 28. 28 8. No classes with more than two instance variables High cohesion, low coupling @jesuswasrasta #TDDMilano
  • 29. 29 9. No getters/setters/properties Tell, don’t ask Feature envy code-smell (extensive use of another class) They violates Open/Closed Principle (S.O.L.I.D.) Anemic Domain anti-pattern @jesuswasrasta #TDDMilano
  • 31. 31 Thanks! Any questions? You can find me at: ▫ @jesuswasrasta ▫ http://about.me/ferdinando.santacroce

Editor's Notes

  1. Non vi è sembrato strano, a tratti? (più lo fate e meno strano sembrerà) Che classi sono emerse? Le regole sono mai andate in contrasto? It’s only OOP, but I like it!
  2. 2) Qual è il senso di queste regole? Capire meglio e fare uso di OOP 7 di 9: encapsulation
  3. 2) Qual è il senso di queste regole? Capire meglio e fare uso di OOP Dont’ use else -> polimorfismo
  4. 2) Qual è il senso di queste regole? Capire meglio e fare uso di OOP Naming strategy