• 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

  1. One level of indentation

  2. Don’t use ELSE

  3. No Primitive obsession - wrap all primitives and Strings

Everything in the universe can be represented with primitive collections

  1. First class collectors should be a class of their own

    Never have a class

  2. One dot per line

Too many dots and you’re probably leaking responsibility

  1. Don’t abbreviate
  2. Keep all entities small

Keep the cognitive load small

  1. No Classes With More Than Two Instance Variables
  1. No getters/setters/properties (Tell, don’t ask)

Any decisions based entirely upon the state of one object should be made inside the object


Refs

  1. https://williamdurand.fr/2013/06/03/object-calisthenics/#8-no-classes-with-more-than-two-instance-variables