Share via


How object calisthenics can save the day

I recently talk to a friend who was migrating a large/complex system he wrote in J++ (ten years ago) to C#. The old system used integers and doubles for a lot of things like amount of money and number of months/days/years. Also over the years he'd learned that a lot of bugs came from the fact that a number was passed that was not what it was supposed to be. For example an integer representing number of months was passed when number of years was expected etc. In order to make the migration safer my friend decided to wrap all these special things into their own classes: Amount, Years, Months Days. This simple approach (rule three of object calisthenics) resulted in just a handful bugs introduced in the migration as well as a handful of old bugs (never found before) also found and fixed. This story could have ended there. But my friend also realized that the Round method in J++ and C# have different default behavior. Easily fixed by implementing a round method on the Amount class.

So remember that object calisthenics is not a set of rule you should always follow but they do teach you good patterns to follow and especially rule three is one of the rules I think you actually could apply at all times.