Fragile Base Class Problem
The Fragile Base Class Problem (FBC) is a malfunction of software that can occur in object-oriented software development when the version of the basic software used is changed and is related to the inheritance mechanism. It can occur when this technique of object orientation is used as an implementation inheritance to reuse code .
The developers of a “fragile” base class , who cannot have exact and complete knowledge of the use of their implementations, are unable to anticipate the negative consequences of a change for specializing classes .
There are various reasons for this, in essence there is a misunderstanding between the developers of the base class and those of the specializations using it. This is mostly due to the fact that the functionality of the base class and also the behavior expected by the specializations are not specified with sufficient precision.
example
A simple example can be BagOfInt
illustrated using a base class , i.e. a container for storing whole numbers. This class contains the following functionality ( methods ):
-
Add
: Adding an element (a number) -
AddAll
: Adding a set of numbers (by passing anotherBagOfInt
) -
GetSize
: Determination of the number of numbers contained -
GetAt
: Access to a specific element using an index
This class is now part of a class library and is TotalizingBagOfInt
expanded into a class , i.e. specialized , by a developer who uses it . The inheriting class has the additional property that it carries the total of all numbers contained in the container. The developer does this by overriding the method Add
in which the grand total is constantly updated.
In a newer version, the developer of the base class now decides AddAll
not to play the method Add
back to the method of the same class as before , but to implement the method differently for reasons of optimization.
After replacing the version of the base class, the specializing class TotalizingBagOfInt
no longer works when the method AddAll
is used. The developer of this class should now also overwrite this method. In the original version he did not do this, for example because he had realized through trial and error that it was not necessary.
literature
- Leonid Mikhajlov, Emil Sekerinski: A Study of The Fragile Base Class Problem (PDF; 355 kB). In: Proceedings of the 12th European Conference on Object-Oriented Programming , pp. 355-382, 1998, ISBN 3-540-64737-6
- Bernhard Lahres, Gregor Rayman: Practical book object orientation. From the basics to implementation . Galileo Press, Bonn 2006, ISBN 3-89842-624-6