Polymorphism
Earlier sections of this chapter covered abstract classes, including the ultimate abstract class, object. It showed how to implement overrides of virtual classes in the object class. This section goes further by explaining how virtual classes are overridden, why, and what good it is. This capability enables an object-oriented programming concept known as polymorphism.
Implementing Polymorphism
To begin, it's useful to get an appreciation of the problem polymorphism solves. The key factor is the ability to dynamically invoke methods in a class based on their type. Essentially, a program would have a group of objects, examine the type of each one, and execute the appropriate method. Here's an example:
using System; public class WebSite ...
Get C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.