Skip to main content

Sign in to CleanKata

Track your progress, earn XP, and unlock every lesson.

By signing in you agree to our Terms of Use and Privacy Policy.

Object Calisthenics

Nine rules to transform how you write object-oriented code.

9 lessons

Use First-Class Collections

Any class containing a collection should have no other member variables — wrapping collections gives filtering, sorting, and rules a semantic and cohesive home.

Earn +70 XP7 min

Keep All Entities Small

No class over 50 lines, no package over 10 files — small classes fit on one screen, force focus, and naturally organize into cohesive packages.

Earn +60 XP6 min

Don't Abbreviate

Abbreviations mask deeper problems — if a name is too long to write out, the method has too many responsibilities. Names should be one or two clear words.

Earn +50 XP5 min

Don't Use the Else Keyword

Replace if/else with guard clauses and early returns — else is usually a sign of unclear flow that can be simplified into a straightforward sequence.

Earn +60 XP6 min

Don't Use Getters/Setters/Properties

Tell, don't ask — instead of getting data to make decisions outside the object, tell the object what to do and let it use its own data.

Earn +80 XP8 min

One Dot per Line

Based on the Law of Demeter — don't reach through an object's internals. Ask the object to do the work instead of navigating its parts.

Earn +70 XP7 min

One Level of Indentation per Method

Each method should do one thing at one level of abstraction — nested control structures are a sign to extract a method.

Earn +60 XP6 min

No Classes with More Than Two Instance Variables

Limiting state to two instance variables dramatically increases cohesion — if you need more, decompose into a hierarchy of collaborating objects.

Earn +70 XP7 min

Wrap All Primitives and Strings

A raw int or string has no domain meaning — wrapping it in a class like Money or Email lets the compiler enforce intent and gives behavior a natural home.

Earn +70 XP7 min