published on in Clean Code Software Design
tags: Clean Code OOP

Clean Code and Object Calisthenics Rules to Better your Object-Oriented Design

I recently discovered Object Calisthenics thanks to a talk[1] I was listening to from Marco Pivetta and I found the name of this “technique” very catchy. I mean, calisthenics is a very demanding way of workout and my first though was it was some kind of extreme posture to approach Object-Oriented software design. I was wrong. There is nothing extreme in this, it is just a condensed list of rules we all have been known for a while thanks to Clean Code.

So, I did my search and I found a nice article[2] of 9 rules that are described as follows:

1. Only 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

They’re easily translatable to things like using Guard Clasules, avoid breaing Demeter’s Law, replace primitives types for Value Objects, encourage Extract Method refactor when your methods are becoming bigger or very nested, appropriate naming, small classes and rule out mutable objects.

References