IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Coder
Search Coder Group:

Advanced
-Collapse +Expand Coder Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Coder Store
PRESTWOODSTORE

Prestwood eMagazine

June Edition
Subscribe now! It's Free!
Enter your email:

   ► KBRole-Based T...Coding & OOObject Orien...   Print This     
  From the November 2015 Issue of Prestwood eMag
 
Coder Object Orientation (OO):
Polymorphism
 
Posted 15 years ago on 3/17/2003 and updated 2/4/2009
Take Away:

A coding technique where the same named function, operator, or object behaves differently depending on outside input or influences. Usually implemented as parameter overloading where the same named function is overloaded with other versions that are called either with a different type or number of parameters. Polymorphism is a general coding technique and other specific implementations are common such as inheritance, operator overloading, and interfaces.

Coder Definition Flashcard:
 A flashcard from our Coder Flashcards Library
 A definition from our Coder Definitions Page

KB100142



Polymorphism -

A coding technique where the same named function, operator, or object behaves differently depending on outside input or influences. Usually implemented as parameter overloading where the same named function is overloaded with other versions that are called either with a different type or number of parameters. Polymorphism is a general coding technique and other specific implementations are common such as inheritance, operator overloading, and interfaces.


The word polymorphism means "many forms". In computer programming, we sometimes expand that simple memory aid as "one name, many forms". More formally, polymorphism is the capability of the same command to be interpreted differently when used with or received by different objects (a single command that works with many objects) and is frequently associated with Object Oriented Programming (OOP).

Parametric Polymorphism: Overloading

The ability of a method to act differently depending on the type or number of parameters passed in (a.k.a. Overloading).

Inheritance-Based Polymorphism

A.k.a. Overriding, Inclusion Polymorphism, Runtime Polymorphism, Dynamic Binding, or Late Binding

Inheritance is a coding element which involves defining methods in a parent class and overriding them with new implementations in child classes. For example, you could define a method in a parent class and override it in descendant classes as needed. When using an object instantiated from one of these classes, you don't actually need to know which method implimentation is used, you just need to know the name of the method or property to use.

Polymorphism allows the software architect to design a dog.run and a cat.run method and then the programmer can decide at development time whether to instantiate a dog or cat object and either way he knows to call the run method to make the object run. If the designer created a MakeDogRun and a MakeCatRun methods, then the programmer would have a hard time remembering different commands and could not easily substitute one for the other (see substitutability below).

Interface-Based Polymorphism

An interface promises to support the same behavior across multiple classes without the baggage of a particular implementation. You can design classes in different descendant lines with common methods and properties without an interface but an interface ensures you implement the methods and properties using the same names and parameters (a common interface).

For example, you may wish to implement an IError interface that specifies a common error tracking interface you will use with all classes you want to log errors. One of your specified methods might be a LogError(pString) function that is required for all classes that implement the IError interface. The LogError method might record a log entry dependant on the class. Perhaps either extra class specific information or perhaps some classes will log errors to a generic log table and others will log to a different destination log table.


(Substitutability)

A.k.a. Subtyping Polymorphism, or Inclusion Polymorphism

Substitutability allows a descendant class to be used anywhere an associated parent class is used. In object oriented programming a variable could refer to one object at one time and then another object another time. This allows the designer of software to create both a dog.run and a cat.run methods and then decide at runtime whether the variable will be a dog or a cat.

Ad-Hoc Polymorphism

Developer defined operator overloading.

More Info

Article:  An Introduction to Object Orientation
Code:  C# Polymorphism
Code:  Delphi Polymorphism
Code:  Delphi Prism Polymorphism
Link:  DotNetCoders.com UML Home Page
Article:  Introduction to OO for the Paradox Community
Article:  Introduction to the Unified Modeling Language
Code:  ObjectPAL Polymorphism (Not Supported)
Article:  OO/UML: Aggregation versus Composition
KB Post:  PSDP Phases compared to UML Workflows
KB Post:  PSDP: Step 2 Planning Overview (Gen & Design Phases)
Code:  VB.Net Polymorphism

Linked Message Board Threads

 9/3 Brown Bag - ISA and Polymorphism in Coding Division MB Topic (1 replies)
 Polymorphism Defined in Object Orientation (OO) MB Topic (4 replies)

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1252A1
Enter key:
Definition Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100142 Counter
13355
Since 4/2/2008
-
   Contact Us!
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


Go ahead!   Use Us! Call: 916-726-5675 


©1995-2018 Prestwood IT Solutions.   [Security & Privacy]