Object-Oriented Programming: Abstraction, Encapsulation, Polymorphism

Polymorphism

You're living in a neighborhood with your family, including your own kids. A few local neighborhood kids are over today for a birthday party, but it is time for them to go home.

So you say, "Alright kids, time to go home."

That's the message. You can call it an event message, or a command, or a function or method call – regardless, it is a message. Time to go home.

But all the kids react to the message in their own ways: TJ goes out the back door, crosses the backyard to the alley, turns a left, walks a few yards, and turns into his own backyard. Khari leaves through the front door, gets on a bike, and takes their getting home the scenic route. Mabel also leaves through the front door, but hops on a skateboard, turns left, and cruises home two blocks away and around the bend. Your own kids hear the message and, wisely, stay put.

To some of those kids, their reaction was unique to them. To some, their reaction was consistent with other kids of the same category (or "class"), such as your own kids. But the big idea is that one single message can be correctly received and interpreted by multiple recipients, each knowing how to react to that message in a way which is appropriate for them.

Poly-morph-ism

  • "poly-": meaning "many"
  • "-morph-": meaning "form"
  • "-ism": makes the word a noun

"Polymorphism," in the context of software design, refers to the idea that a valid recipients of a "message" (event, method call, etc.) may take many forms and still be correct. Computer science borrows this term from the field of biological science.