Fragile base class
From Wikipedia, the free encyclopedia
The fragile base class problem is a fundamental architectural problem of object-oriented programming systems where base classes (superclasses) are considered "fragile" because seemingly safe modifications to a base class, when inherited by the derived classes, may cause the derived classes to malfunction. The programmer cannot determine whether a base class change is safe simply by examining the base class's methods in isolation.
Sometimes the fragile binary interface problem is referred to as the fragile base class problem. The two problems are related but very different.
One possible solution is to make instance variables private to their defining class and force subclasses to use accessors to modify superclass states. A language could also make it so that subclasses can control which inherited methods are exposed publicly. These changes prevent subclasses from relying on implementation details of superclasses and allow subclasses to expose only those superclass methods that are applicable to itself.
Also, in general, programmers should program to interfaces rather than concrete implementations.
[edit] Solutions
- Objective-C has Categories
- Ruby has Mixins
- Component Pascal deprecates Supercalls
[edit] See also
- Implementation inheritance
- Inheritance semantics
- Software brittleness
- Virtual Inheritance (object-oriented programming)
[edit] External links
- Why Extends is Evil - An example in Java
- A Study of The Fragile Base Class Problem - Scientific description and analysis of the fragile base class problem