Understanding Polymorphism

The final point to be made here is Polymorphism. All this means is the ability to call methods with the same name and have it mean different things based on the object you are working on.

For example, let's take our Light objects. All have a method called Toggle which turns the light on and off. Support, now, that I were to create an entirely different object: a telephone. The telephone object may or may not have anything to do with a light object but there is a method attached to it which is also called Toggle which does something.

Now, let's take a look at this bit of code:


oLight = CREATEOBJECT("Light")
oPhone = CREATEOBJECT("Telephone")
oLight.Toggle    &&Runs the Toggle method from 
                &&the Light object
oPhone.Toggle    &&Runs the Toggle method from 
                &&the Phone object