New features without editing old codeadvanced
When each variation is its own class behind a shared base, a new one arrives as a new file and nothing that already works is opened — the switch you deleted was the thing every feature used to edit.
Three methods switch on the same channel code. Product wants Mobile Money next, which today means editing all three. Replace the code with a class per channel, then add Mobile Money as one new class.
See alsoOne caller, many shapesThe same switch-to-classes move in JavaScript, graded by running the code.
No switch on a channel code, a class per channel overriding an abstract base, Checkout using only the base, and Mobile Money added as one class.
Published in full, before you start — every point is one of these and there is nothing else.
When each variation is its own class behind a shared base, a new one arrives as a new file and nothing that already works is opened — the switch you deleted was the thing every feature used to edit.
A switch on a type must be edited every time a type is added, and there is always more than one of them; asking the object instead means a type invented tomorrow works in code written today.
Anywhere the parent works the child must work too — and a subclass that compiles perfectly can still break the first caller who relied on something the parent quietly promised.