In this repository you can find all the exercises for the Object Calisthenics Workshop, by Dev Dojo IT.
Object Calisthenics is a programming exercise and a set of coding rules designed to promote better object-oriented code through constraint-based training. The term "calisthenics" comes from physical exercise, suggesting that these rules act as programming exercises to strengthen your coding abilities and discipline.
Object Calisthenics consists of 9 specific rules that force developers to write code with better:
- Encapsulation
- Maintainability
- Readability
- Testability
- Reusability
These rules were initially formulated by Jeff Bay in the book "ThoughtWorks Anthology" and are meant to be challenging constraints that push developers to think differently about how they structure their code.
Forces you to break down complex methods into smaller, focused ones
Encourages early returns and polymorphism over conditional logic
Promotes domain modeling by creating meaningful types instead of using raw primitives
Collections should be wrapped in their own class with behaviors specific to what the collection contains
Prevents method chaining and the "train wreck" pattern, enforcing the Law of Demeter
Names should be clear, descriptive, and unabbreviated
Classes should be no more than 50 lines and packages no more than 10 files
Forces you to think harder about proper decomposition and cohesion
Tell, don't ask - objects should expose behavior, not state
The strict rules of Object Calisthenics aren't necessarily meant to be followed in all production code. Rather, they serve as:
- A training exercise to develop better coding habits
- A way to identify code smells and weaknesses in design
- A tool to push developers toward more object-oriented thinking
- A practical approach to reinforce SOLID principles
When developers practice these constraints, they often discover new patterns and approaches that can improve their everyday coding practices, even when not strictly adhering to all nine rules.
Object Calisthenics ultimately helps developers write more maintainable code by building muscle memory for good object-oriented design principles.