Part 2 of 6 · 2 min read
Axes of change
Ask what is likely to vary.
Think of a power strip. The strip does not know which devices will be plugged in. Its sockets are the same, and new devices need no rewiring. The strip is built around the idea that the devices vary and the sockets do not.
An axis of change is a part of the requirement that is likely to vary. Fee rules, payment vendors, notification channels and discount rules are typical. For each axis, the design puts an interface at the point of variation, so a new variant is a new class and existing classes stay untouched. This is the open-closed principle of Level 2, module 2, and most of the patterns of Levels 3 and 4 are ways to do it.
CC states the reason. For most systems, change is continual, and each change risks breaking the rest. A class that must be opened up for every change carries that risk each time. CC's example is a class that builds database statements, with one method per kind of statement. A new kind of statement means editing the class and retesting it all. CC's advice is to split it so that each statement kind is its own class under a common parent, so adding a kind touches no existing class.
CC adds a balance. The main trigger for action is change itself. If a class is complete and nothing is expected to change, leave it alone. As soon as you find yourself opening a class again and again, then fix the design. This echoes YAGNI (Level 2, module 7): do not build for a change that nobody has asked for or expects.
A short list of questions finds the axes:
- Which words in the requirement are a list of types or kinds? (payment methods, vehicle types)
- Which rules are numbers that the business may change? (fees, limits)
- Which parts talk to the outside world? (vendors, storage, messages)
- What did the interviewer say "for now" about?
Axis of change
An axis of change is one way in which a requirement is likely to change, such as a new kind of discount or a new payment vendor.
Example: "discount rules" in a pricing system.
Check yourself: 1. What does CC say is the main trigger for reworking a class? 2. Name two axes of change in a ticket-booking system. 3. How is a new variant added at a good axis?