Fragile base class

The Fragile Base Class Problem ( FBC ) is a malfunction of software, which can occur when changing versions of the basic software used in the object-oriented software development and related to the inheritance mechanism. It can occur when this technique of object orientation is used as implementation inheritance for reusing code.

The developer of a " fragile " base class that can not have full and complete knowledge of the use of their implementations are not able to anticipate the negative consequences that result for spezialisierende classes thereof for a change.

The reasons for this are manifold, essentially is a misunderstanding between the developers of the base class and those of the specializations used before. This is mostly because the functionality of the base class and also the expected behavior of the specializations are not sufficiently precise specified.

Example

A simple example can be illustrated by means of a base class BagOfInt, ie a container for storing integers. This class includes the following functionality (methods):

  • Add: Add an element ( a number)
  • AddAll: Add a set of numbers ( by passing a different BagOfInt )
  • GetSize: Determining the number of figures contained
  • GetAt: access to a particular element using an index

This class is now part of a class library and is extended by a developer who uses these to a class TotalizingBagOfInt so specialized. The inheriting class has the additional property that it carries the sum total of all the numbers contained in the container. The developer achieves this by overriding the Add method in which the total sum is constantly being updated.

In a more recent version is now decided by the developers of the base class that AddAll method no longer have to play back to the Add method of the same class, but to implement the method for optimization reasons otherwise.

After replacing the version of the base class now does the spezialisierende class TotalizingBagOfInt not more if the AddAll method is used. The developer of this class should now also override this method. In the original version he did not, for example, because he had recognized by trial and error that it was not necessary.

344214
de