Tuesday, April 21, 2015

The Problem of the Fragile Base Class

If (almost) all classes inherit from a single base class in a system, we get the problem of the fragile base class: a change to that single base class can break subclasses in non-obvious ways.

But this problem must be weighed against the advantages of a single base class. The foremost advantage is probably that one can add a capability to the base class and have it available to every class in the system if they all inherit from that base class.

What's more, the very problem can be an advantage: if some capability is provided in the base class, and there is a problem with it, the fix will also be all in one place!

The upshot: if you use a single base class, be very careful about changing it!

No comments:

Post a Comment

Open Source Software and Skin In the Game

I have been tinkering in the Haskell programming language recently. Trying to up my game, I have begun reviewing and working on issues in th...