<< Chapter < Page | Chapter >> Page > |
I recommend that you also study the other lessons in my extensive collection of online programming tutorials. You will find a consolidated index at www.DickBaldwin.com .
The first of three major characteristics of an object-oriented program is encapsulation, which I explained in a previous lesson. The second of the threemajor characteristics is inheritance, and the third is polymorphism. I also explained inheritance in a previous lesson. I will explainpolymorphism from a big-picture viewpoint in this lesson.
Not as complicated as it sounds
Upon first reading, you may conclude that polymorphism sounds extremely complicated. However, polymorphism is more difficult to explain than it isto program. Once you have read the description and have seen the concept applied to an actual program, you will (hopefully) conclude that it is not as complicated as it sounds.
What is polymorphism?
Polymorphism is a word taken from the Greek, meaning "many forms", or words to that effect.
The purpose of polymorphism as it applies to OOP is to allow one name to be used to specify a general class of actions. Within that general class ofactions, the specific action that is applied in any particular situation is determined by the type of data involved.
Polymorphism in ActionScript comes into play when inherited methods are overridden to cause them to behave differently for different types of subclassobjects.
Overriding versus overloading methods
If you read much in the area of OOP, you will find the words override and overload used frequently. (This lesson deals with overriding methods and does not deal with overloading.)
Some programming languages such as C++, Java, and C# support a concept known as method or constructor overloading. However, ActionScript 3 does notsupport method or constructor overloading. Overriding a method is an entirely different thing from overloading a method even for those languages thatsupport overloading.
Modify the behavior of an inherited method
Polymorphism can exist when a subclass modifies or customizes the behavior of a method inherited from its superclass in order to meet the special requirementsof objects instantiated from the subclass. This is known as overriding a method and requires the use of the override keyword in ActionScript.
Override methods differently for differentsubclasses
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?