Object oriented programming has a few core concepts. One of the most fundamental is Polymorphism. Here’s a really simple explanation:

  • Polymorphism is the ability to hijack an existing inherited method and add functionality to it.

If you’ve been reading this series on OOP principles (and you should have been!) then you’ll remember Inheritance. Here’s a quick recap:

***** START INHERITANCE RECAP *****

Let’s say you have a class to create a ‘Car’:

And now create a ‘FastCar’ class that inherits from ‘Car’:

Now FastCar has inherited all the properties / functions / whatevers from ‘Car’.

***** END RECAP *****

Polymorphism

So how does polymorphism fit in here? Well let’s say we wanted to Print details about the ‘FastCar’. Of course we can just call PrintDetails (as it’s inherited from ‘Car’). BUT….what if we wanted to change the PrintDetails function? That’s where polymorphism waltzes in the door to save the day.

Polymorphism caterpillar and butterfly
Polymorphism – Changing a method or function to do something extra that it couldn’t do before!

We can ‘override’ the original PrintDetails function, execute it as normal (using the ‘super’ keyword) and then add extra functionality!

So you’ll often see polymorphism associated with the word ‘override’. If you look at the class definition it will also inherit from another base class.

And the advantage of all this? Why, as if you need to ask….

Write less code. Avoid repetition 🙂

Where to go Next

This tutorial comes straight out of The Complete iOS Developer Course. Over 40 hours long it contains everything you need to create awe inspiring apps fast!

Click here to check it out!

What is Object Oriented Programming? Polymorphism

Leave a Reply

Your email address will not be published. Required fields are marked *

Share This

Want this Post in Easy to Understand Video Form?

Then get the Complete iOS Developer Course. Over 50 hours of pure Swift coding goodness designed to turn you into a coding master!

One Time Offer - $9! Click to Get it!



WARNING: Once this box is closed the offer will not be shown again.

Thank you!