We have reached the end of the exercise – Nine Steps to Better Software Design, presented at chapter Object Calisthenics by Jeff Bay in The ThoughtWorks Anthology book from the Pragmatic Programmers.
Eight of these nine rules are simply ways to visualize and implement the Holy Grail of object-oriented programming—the encapsulation of data. In addition, another drives the appropriate use of polymorphism (not using else and minimizing all conditional logic), and another is a naming strategy that encourages concise and straightforward naming standards, without inconsistently applied and hard-to-pronounce abbreviations.
Tip from the author:
In the long run, you will inevitably find that these rules contradict each other in some situations or that applying the rules leads to degenerate results. For the purpose of the exercise, however, spend 20 hours and 1,000 lines writing code that conforms 100% to these rules. You will find yourself having to break old habits and change rules that you may have lived with for your whole programming life. Each of the rules has been chosen such that if you follow it, you will encounter situations that would typically have an obvious (but perhaps incorrect) answer that is not available to you.
Following these rules with discipline will force you to come up with the harder answers that lead to a much richer understanding of objectoriented programming. If you write 1,000 lines that follow all these rules, you will find that you have created something completely different from what you expected. Follow the rules, and see where you end up. If you keep working at it, the code you are writing might conform to these rules without any conscious effort on your part.
If you have missed some part of this series, check out the list below with all related posts.
- 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.
Happy coding! ; )