Polymorphism - Define In Just Two Sentences

Mark Testa picture Mark Testa · Jan 3, 2009 · Viewed 92.7k times · Source

I've looked at other definitions and explanations and none of them satisfy me. I want to see if anybody can define polymorphism in at most two sentences without using any code or examples. I don't want to hear 'So you have a person/car/can opener...' or how the word is derived (nobody is impressed that you know what poly and morph means). If you have a very good grasp of what polymorphism is and have a good command of English than you should be able to answer this question in a short, albeit dense, definition. If your definition accurately defines polymorphism but is so dense that it requires a couple of read overs, then that's exactly what I am looking for.

Why only two sentences? Because a definition is short and intelligent. An explanation is long and contains examples and code. Look here for explanations (the answer on those pages are not satisfactory for my question):

Polymorphism vs Overriding vs Overloading
Try to describe polymorphism as easy as you can

Why am I asking this question ? Because I was asked the same question and I found I was unable to come up with a satisfactory definition (by my standards, which are pretty high). I want to see if any of the great minds on this site can do it.

If you really can't make the two sentence requirement (it's a difficult subject to define) then it's fine if you go over. The idea is to have a definition that actually defines what polymorphism is and doesn't explain what it does or how to use it (get the difference?).

Answer

Jon Skeet picture Jon Skeet · Jan 3, 2009

Polymorphism allows the expression of some sort of contract, with potentially many types implementing that contract (whether through class inheritance or not) in different ways, each according to their own purpose. Code using that contract should not(*) have to care about which implementation is involved, only that the contract will be obeyed.

(*) In the ideal case, anyway - obviously quite often the calling code has chosen the appropriate implementation very deliberately!