Really understanding Polymorphism

Today’s blog is much less the normal in that I will not be providing any coding or examples of anything I have come across. Today, I am going to talk about an interesting topic that is both fundamental to software development in the OOP world, but often misunderstood. Me Included. Yes I know, I shouldn’t admit it, but I also even though thinking I really understood polymorphism and have answered correctly on any interview question when asked what it is, failed the test when reading this blog by an excellent blogger named John Sonmez.

The test was “Can you provide an actual analogy for polymorphism”. The key word here is analogy, not example. I have often said (as taught by my awesome parents long ago), if you can give an analogy for something, then you truly understand it. If not, and can only come up with an example or rigid definition, chances are, you don’t really understand the concept. This doesn’t just apply to programming, but really anything.

So what does John say is a good analogy to polymorphism? A Blu-ray player. Now you are probably thinking like I was… huh?? Well, it actually makes sense when you think about it for a minute. what does a player do? it plays Blu-ray discs, but it also plays regular DVD’s right? So the player acts as the interface to the media (DVD’s and Blu-Ray Discs in this case). In each scenario of placing the different media in the player, a different implementation takes place ie. a different process is done to “play” the movie. So Blu-ray player would be the interface / abstract class, the DVD and Blu-ray Disc would be the classes that inherit from Blu-ray player and then Blu-ray player would contain a method called “Play()” that both Disc classes would be required to implement.

It was an interesting enough article that I thought would be a great thing to send out to my readers and talk a little about what he is explaining so that next time you need to explain what polymorphism is, you are ready to impress.


As always Happy Coding…. and happy Memorial Day a few days early Smile


About Gregg Coleman

I am Senior-level Software Engineer working primarily these days with .NET. I have a good working knowledge of ASP.NET MVC, Web Forms, WCF web services and Windows Services. I spend much of my time in the Web Services (SOAP and REST) world in my current job designing and implementing various SOA architectures. I have been in the software engineering industry for about 6 years now and will not now nor ever consider myself an "expert" in programming because there is always so much to learn. My favorite thing about designing software is there are always new emerging technologies and something to learn every day! My current job has me spending much of my job on the bleeding edge of technologies and changing gears all the time, so I'm never bored and always challenged. On my spare time I enjoy weight training, reading and venturing to new places near by. Of course programing and learning new technologies are another hobby of mine.
This entry was posted in .NET, .NET 4.5, C#, Programming, Programming Paradims and tagged , , , , , , . Bookmark the permalink.

2 Responses to Really understanding Polymorphism

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s