Lecture overview -- Keyboard shortcut: 'u'  Previous page: Cloning in C# -- Keyboard shortcut: 'p'  Next page: The Visitor design pattern -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 32 : 37
Object-oriented Programming in C#
Abstract classes, Interfaces, and Patterns
The fragile base class problem

If all methods are virtual it is possible to introduce erroneous dynamic bindings

This can happen if a new method in a superclass is given the same name as a dangerous method in a subclass

/user/normark/oop-csharp-1/sources/c-sharp/fragile-subclass-problem/1/fragile.csThe initial program.


/user/normark/oop-csharp-1/sources/c-sharp/fragile-subclass-problem/1/outputOutput of original program.


/user/normark/oop-csharp-1/sources/c-sharp/fragile-subclass-problem/2/fragile.csA revised program with a new version of class A with a method M2.


/user/normark/oop-csharp-1/sources/c-sharp/fragile-subclass-problem/3/fragile.csThe revised version with method A.M2 being virtual.


/user/normark/oop-csharp-1/sources/c-sharp/fragile-subclass-problem/3/outputOutput of revised program.


/user/normark/oop-csharp-1/sources/c-sharp/fragile-subclass-problem/4/fragile.csThe revised version with method A.M2 being hidden.


/user/normark/oop-csharp-1/sources/c-sharp/fragile-subclass-problem/4/outputOutput of revised program.