In a nutshell
A way to write really beautiful object-oriented code with draconian limitations. Start with explaining the rules. Be mindful of caveats.
Rules
9 rules are as follows:
- Use only one level of indentation per method
- Don’t use the else keyword
- Wrap all primitives and strings
- Use only one dot per line
- Don’t abbreviate
- Keep all entities small
- Don’t use any classes with more than two instance variables
- Use first-class collections
- Don’t use any getters/setters/properties
Don’t use the else keyword
And if (true) {}; if (false) is disallowed also. 😛 Somebody always asks.
Use only one dot per line
Caveat for some languages, think Ruby and RSpec for instance. Also problem with fluent interfaces. Both cases are allowed as exceptions to the rule.
Don’t use any classes with more than two instance variables
That one can be difficult, but do try. If you have a collection, see next one.
Use first-class collections
My personal favourite. If you have a collection, wrap it in a type class and make instance of that type class one of two allowed instance variables. Then provide API to underlying collection in a type class.
Don’t use any getters/setters/properties
No public or protected fields that you can access without field accessor. No field accessors. That is equivalent to changing the way you do OO – not by direct state manipulation on another object.
More reading
I shall add more links here, which I perused once I was preparing for my OC, including my own blog post (now a draft) about how it went – later.
A very good starting point for me was Mark Needham’s account of Object Callisthenics.