Lecture overview -- Keyboard shortcut: 'u'  Previous page: Virtual methods in C# -- Keyboard shortcut: 'p'  Next page: Overriding the Equals method in a class -- 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 36 : 40
Object-oriented Programming in C#
Specialization, Extension, and Inheritance
Practical use of virtual methods in C#

A client of different types of bank account classes illustrates a typical use of virtual methods

 

/user/normark/oop-csharp-1/sources/c-sharp/bank-account/inheritance-1/account-client.csUse of virtual bank account methods.


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/inheritance-1/without-dynamic-binding/account-client.csAdding interests without use of dynamic binding - AddInterest is not virtual.


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/inheritance-1/outputOutput from the bank account programs.


The use of virtual methods - and dynamic binding - covers a lot of type dispatching which in naive programs are expressed with if-else chains