Polymorphism

Polymorphism lets one piece of code work with many kinds of objects. You will treat derived objects as their base class and let each one behave in its own way.

Updated

Polymorphism in C#

  1. Polymorphism in C#: an overview (Apprentice): Polymorphism means "many forms". An object can be seen in more than one way, and code can work with whichever way it needs.
  2. Changing Roles (Apprentice): Through the day, people treat Chloe as a student, a singer or an athlete. Each sees only the role it needs. Polymorphism shifts focus in the same way.
  3. Polymorphism with Base Classes (Journeyman): A base class variable or list can hold any derived object, and calling a virtual method runs each object's own override. Use is to reach a derived class's own members.

Exercise: Polymorphism

  1. Exercise: Polymorphism (Journeyman): Write a café Order that holds any mix of menu items in one List<MenuItem>, and works out the total, a meal-deal discount and the receipt, letting each item price itself.