Object Calisthenics: Rule 9: Don’t use any getters, setters or properties

This is my favorite rule. I think it's a forgotten guideline in OO design to tell objects what to do with their state rather than asking for their state. Applying this rule to code changed the way I had to write code most of all rules. Keeping classes under 50 lines changed a lot but this rule is much harder to apply than just extracting methods and classes. You really have to rethink the way you write your code I think. Actually I think that if you're going to try object calisthenics and only want to use one rule, this is probably the rule you should use.

Comments (1)
  1. Peter says:

    Thanks for posting all these! I think you're the only person in the entire internet who has both a) devoted time to solving the problem, and b) blogged about it!

    For me, I agree that #9 has caused the most significant restructuring of object responsibilities. Unfortunately rule #9, combined with Rule #3 (wrap all primitives and strings), and Rule #2 (Don't use the ELSE keyword), has left me at an ugly crossroads.

    I'm getting the idea that squeezing the last bits of object calisthenics compliance out of a solution is just not worth it. For me, I'm down to exactly two rule violations, and "fixing" either will require bending the rules. So, for inspiration I'm looking around at what everyone else is saying about object calisthenics…and your series of blog posts is about all I can find on the subject.

Comments are closed.

Skip to main content