Lecture Notes for Advanced Programming II

15 April 2004 - Implementing Subtype Polymorphism


Mixing static and dynamic look-up in the same class is the basis for a proposed solution to the fragile base class problem.

The fragile base-class problem occurs when a child class makes some assumptions about inherited methods in a parent class, and the inherited methods change in the parent class in such as way as to violate the child's assumptions, breaking the child.

The proposed solution is based on the observation that the fragile base-class problem almost always arises when dynamic look-up causes the child to capture a method call in the parent. Preventing such capture entails making methods protected and non-virtual, which insures that the implementation remains rooted in the parent class. Public methods, on the other hand, may remain virtual because the child's assuptions about those methods are no different from any other client of the parent class.


This page last modified on 21 May 2004.