- Object Calisthenics are programming exercises, formalized as a set of 9 rules invented by Jeff Bay in his book The ThoughtWorks Anthology
- These rules focus on maintainability, readability, testability, and comprehensibility of your code
The 9 Rules
-
One level of indentation
-
Don’t use ELSE
-
No Primitive obsession - wrap all primitives and Strings
Everything in the universe can be represented with primitive collections
-
First class collectors should be a class of their own
Never have a class
-
One dot per line
Too many dots and you’re probably leaking responsibility
- Don’t abbreviate
- Keep all entities small
Keep the cognitive load small
- No Classes With More Than Two Instance Variables
- No getters/setters/properties (Tell, don’t ask)
Any decisions based entirely upon the state of one object should be made inside the object