Polymorphism

You might hear of polymorphism referred to as the third pillar of OOP. But if I wrote it in that order above, my mnemonic would no longer work!

Polymorphism is a Greek word that refers to something that has many shapes or forms. We will see an example of this in the Cricket Score Tracking app later on. Just remember that it has two distinct aspects:

  • During runtime, a class that is derived from a base class may be treated as an object of the class it inherits. This is seen in parameters, collections, and arrays.
  • The base class can define virtual methods that the derived class would then override. The derived class then provides their own implementation of the overridden methods.

Polymorphism is a very powerful feature in OOP. ...

Get C# 7 and .NET Core 2.0 Blueprints 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.