Fragile Base Class Problem

from Wikipedia, the free encyclopedia

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 BagOfIntillustrated 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 another BagOfInt)
  • 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 TotalizingBagOfIntexpanded 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 Addin which the grand total is constantly updated.

In a newer version, the developer of the base class now decides AddAllnot to play the method Addback 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 TotalizingBagOfIntno longer works when the method AddAllis 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