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

Career Fair Organization

A dark thought came into my mind. I imagined the hosts of career fairs plan eight hours worth of events for their participant companies. ...