A fragile base class is the fundamental problem of object-oriented programming .
Description
The problem of a fragile base class is that even minor changes in the implementation details of a base class can introduce an error into derived classes. In the worst case, this leads to the fact that any successful modification of the base class requires a preliminary study of the entire inheritance tree, and it is often impossible (without creating errors) even in this case.
The problem of a fragile base class greatly reduces the value of inheritance .
In general, the problem is not solved, and is one of the major shortcomings of the PLO.
The problem can be generalized to systems developed not in OOP-languages, and not using the concept of "class". Any reuse of ready-made code (without copying) as part of a new code may entail such a problem.
In modern programming paradigms, developed under the influence of the PLO, the concepts of “connections” and “connectivity” are used, and the quality of design is determined by the management of connections, which, in particular, implies a weakening of connections. Inheritance in the understanding of the PLO creates the strongest possible relationship, and thus should be used with great care.
The high complexity of developing frameworks compared to the development of tools described in the book on patterns of the so-called “ gang of four ” is determined, in particular, by the easy appearance of the “fragile base class” in frameworks and the complexity of dealing with this problem.
Possible methods of struggle
Replace inheritance with aggregation . During aggregation, the nested object of the base class is explicitly described as part of the object of the derived class, and the derived class can use only the public interface of the base class. Thus, the derived class cannot depend on the details of the implementation of the base class, which solves the problem.
See also
- Component Oriented Programming