IT SOLUTIONS
916-726-5675
-Collapse +Expand

Coder

Search Coder Group:

Advanced
-Collapse +Expand Coder Group Home
-Collapse +Expand Message Board
-Collapse +Expand Knowledge Base
-Collapse +Expand Coder Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Coder Store
PRESTWOODSTORE
-Collapse +Expand Members Only
Prestwood Tip Jar
Tip Jar
Finding something useful?

Add to the
Tip Jar!

Prestwood eMagazine

Subscribe now!
Enter your email:


   Prestwood ITPrestwoodBoardsKBRole-Based Tech TalkCoding & OOObject Orientation (OO)   
Go To Random Article
  From the February 2009 Issue of Prestwood eMag
 
Coder Object Orientation (OO):
Polymorphism
By Mike Prestwood
3/10/2003, Last updated 2/4/2009
 
Coder Definition Flashcard:
 A flashcard from our Coder Flashcards Library
 A definition from our Coder Definitions Page


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 PS Staff Business MB Topic (1 replies)
 Polymorphism Defined in Object Orientation (OO) MB Topic (4 replies)
Definition Contributed By Prestwood staff member Mike Prestwood:
mprestwood
Email Approved! E CA USA

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.


Comments

0 Comments.
Would you like to comment? Reply? Ask a question? Say thanks?
Add Comment



 KB Article #100142 Counter
2354
Since 4/2/2008

Sponsored Ad
Brought to you by Prestwood IT Solutions
We hope you are enjoying our knowledge base! We welcome your participation in our open online community. As the caretakers, we pay our staff to moderate, edit, and contribute free content here in an effort to promote our software development company. Keep us in mind if you or your company needs help. Whether you need a single developer or a team, consider Prestwood. We are an American company that keeps jobs in America (no off shoring and no need for H-1B developers). Our hope is that you will put some or all of your development tasks in our hands. We specialize in hourly help (1 hour minimum), custom websites from $2k to $40k, business database applications from $5k to $60k, and enterprise application development starting from $20k. Talented Developer?
If you are a talented developer and would like to work with us, start by filling out our Register for Work form.
 
Mike Prestwood
Need service or help?
Have a question? Contact Us.
--Mike Prestwood
Follow us on: 
805 People Online Now!!  
Online Now: Sign In to see who's online now!  Not a member? Join Prestwood now. It's free!
1995-2010 Prestwood IT Solutions.   [Security & Privacy]   Made in the U.S.A..   No H1-B.   No offshoring.