SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
Object Calisthenics
       @krolow
WTF?
● code is hard to understand, test and
  maintain
● OO will save us!
● it's hard the transaction of paradigms

     Procedural --- to --- OOP
● Qualities matters:
   ○   cohesion
   ○   loose coupling
   ○   no redundancy
   ○   encapsulation
   ○   testability
   ○   readability
so what is it about?

It's an exercise, a practice to help you to write
good oriented-object code!
The RULES
#1 One level of indentation per method
#2 Don't use ELSE keyword
#3 Wrap all primitives and String
#4 First class collections
#5 One dot per file
#6 Don't abbreviate
#7 Keep all entities small
#8 No classes with more than two instances
variable
#9 No getters/setters/properties
#RULE1
You shall not ident more than once!
#RULE2
You shall not have "else"
#RULE3
  You shall encapsulate the primitives types

not totally applicable in PHP because of performance issues



but... we can do this with other types...
#RULE4
Your collection shall not have other members
variable
#RULE 5
 You shall use one dot per file, so you know
 each object has the responsible

not totally applicable in PHP...
... but nested calls
  ● show some problems of encapsulation
       make harder to debug
       ...

 ●   we can use...
            in chain of get and setters
            in chain of objects with a fluent interface
#RULE 6
  You must not abbreviate

why I should abbreviate?
 ● because I use the name several times...
 ● .... maybe your method is to heavily and you should remove
     duplication
 ● or because the names are too long...
 ● ... maybe you are misplacing responsibilities or there is a missing
     class...

Avoid also duplicate of words...
#RULE 7
 Keep your entity classes smaller!

50 rows by class
10 classes by package...

maybe 100 rows by class and 15 by package it's also OK!
#RULE 8
  Class shall have less than 2 instance variables

Yep quite hard this... but let's try...

with this we can decomposition, we can separate the concerns...

maybe 5 variables it's also okay don't you think?
#RULE 9
  You shall not have getter and setters

WTF?

Yeah, PHP it's not possible apply that :|

BUT...

If we apply the #RULE 8 we may get this!
Object Calisthenics

Contenu connexe

Tendances

TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
Patrick John Pacaña
 

Tendances (20)

TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Typescript Basics
Typescript BasicsTypescript Basics
Typescript Basics
 
Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014
Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014
Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014
 
Typescript overview
Typescript overviewTypescript overview
Typescript overview
 
Typescript - MentorMate Academy
Typescript - MentorMate AcademyTypescript - MentorMate Academy
Typescript - MentorMate Academy
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 
Redis - from client to execution
Redis - from client to executionRedis - from client to execution
Redis - from client to execution
 

En vedette

En vedette (7)

Machucando o código - Técnicas para escrever um código com uma maior legibil...
Machucando o código - Técnicas para escrever um código com uma maior legibil...Machucando o código - Técnicas para escrever um código com uma maior legibil...
Machucando o código - Técnicas para escrever um código com uma maior legibil...
 
programming.success - carreira de programador
programming.success - carreira de programadorprogramming.success - carreira de programador
programming.success - carreira de programador
 
Empregado like a boss
Empregado  like a boss Empregado  like a boss
Empregado like a boss
 
Deixando de ser moleque com PHP
Deixando de ser moleque com PHPDeixando de ser moleque com PHP
Deixando de ser moleque com PHP
 
Vagrant - ambiente de desenvolvimento virtualizado
Vagrant - ambiente de desenvolvimento virtualizadoVagrant - ambiente de desenvolvimento virtualizado
Vagrant - ambiente de desenvolvimento virtualizado
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Microservices - Quebrando gigantes em pequenos
Microservices - Quebrando gigantes em pequenosMicroservices - Quebrando gigantes em pequenos
Microservices - Quebrando gigantes em pequenos
 

Similaire à Object Calisthenics

Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
Edorian
 

Similaire à Object Calisthenics (20)

Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
 
OOPs Concepts.pptx
OOPs Concepts.pptxOOPs Concepts.pptx
OOPs Concepts.pptx
 
클린 테스트
클린 테스트클린 테스트
클린 테스트
 
Me, my self and IPython
Me, my self and IPythonMe, my self and IPython
Me, my self and IPython
 
Clean Code
Clean CodeClean Code
Clean Code
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
 
Data Science Salon: Deep Learning as a Product @ Scribd
Data Science Salon: Deep Learning as a Product @ ScribdData Science Salon: Deep Learning as a Product @ Scribd
Data Science Salon: Deep Learning as a Product @ Scribd
 
Ruby for .NET developers
Ruby for .NET developersRuby for .NET developers
Ruby for .NET developers
 
(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Namespace inPHP
Namespace inPHP Namespace inPHP
Namespace inPHP
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
 
Clean code - DSC DYPCOE
Clean code - DSC DYPCOEClean code - DSC DYPCOE
Clean code - DSC DYPCOE
 
Recurrent Neural Networks in 10 minutes or less
Recurrent Neural Networks  in 10 minutes or lessRecurrent Neural Networks  in 10 minutes or less
Recurrent Neural Networks in 10 minutes or less
 
Ruby
RubyRuby
Ruby
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
 
Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.Let's PHP in a better way! - Coding Recommendations.
Let's PHP in a better way! - Coding Recommendations.
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Object Calisthenics

  • 2. WTF? ● code is hard to understand, test and maintain ● OO will save us! ● it's hard the transaction of paradigms Procedural --- to --- OOP ● Qualities matters: ○ cohesion ○ loose coupling ○ no redundancy ○ encapsulation ○ testability ○ readability
  • 3. so what is it about? It's an exercise, a practice to help you to write good oriented-object code!
  • 4. The RULES #1 One level of indentation per method #2 Don't use ELSE keyword #3 Wrap all primitives and String #4 First class collections #5 One dot per file #6 Don't abbreviate #7 Keep all entities small #8 No classes with more than two instances variable #9 No getters/setters/properties
  • 5. #RULE1 You shall not ident more than once!
  • 6. #RULE2 You shall not have "else"
  • 7. #RULE3 You shall encapsulate the primitives types not totally applicable in PHP because of performance issues but... we can do this with other types...
  • 8. #RULE4 Your collection shall not have other members variable
  • 9. #RULE 5 You shall use one dot per file, so you know each object has the responsible not totally applicable in PHP... ... but nested calls ● show some problems of encapsulation make harder to debug ... ● we can use... in chain of get and setters in chain of objects with a fluent interface
  • 10. #RULE 6 You must not abbreviate why I should abbreviate? ● because I use the name several times... ● .... maybe your method is to heavily and you should remove duplication ● or because the names are too long... ● ... maybe you are misplacing responsibilities or there is a missing class... Avoid also duplicate of words...
  • 11. #RULE 7 Keep your entity classes smaller! 50 rows by class 10 classes by package... maybe 100 rows by class and 15 by package it's also OK!
  • 12. #RULE 8 Class shall have less than 2 instance variables Yep quite hard this... but let's try... with this we can decomposition, we can separate the concerns... maybe 5 variables it's also okay don't you think?
  • 13. #RULE 9 You shall not have getter and setters WTF? Yeah, PHP it's not possible apply that :| BUT... If we apply the #RULE 8 we may get this!