Comparison
Fragile base classvsTemplate method
Fragile base class
a harmless-looking change inside the parent broke three subclasses in another repository that you had never seen.
The failure mode where a superclass cannot be changed safely because subclasses depend on its internal call structure, not merely its public contract. It is why inheritance across a library boundary is a much larger promise than it looks: the moment someone extends your class, its private call sequence is part of your API. This is the concrete cost that `composition-over-inheritance` is arguing against.
Full entry →Template method
the base class runs the five steps in order and leaves two of them abstract for you to write.
Defining the skeleton of an algorithm in a base class and deferring specific steps to subclasses. It is the inheritance-shaped sibling of strategy: same goal — vary part of an algorithm — with the variation bound at compile time by subclassing rather than at runtime by composition. It is the most common accidental producer of a fragile base class, because the ordering and the calls between steps become an unwritten contract.
Full entry →