34 | Chapter 1: Object-Oriented Programming, Design Patterns, and ActionScript 3.0
All the changes are revealed in the line,
doDemo.abstractMethod( );
Even though the line is the same as Example 1-23, the output window reveals that a
good deal has changed:
This is the new abstractMethod!!
Made just one little important change.
But this still works just fine!
I'm a concrete method from an abstract class
What’s important isnotthat it made the changes. The point that you need to con-
sider carefully is the fact that such changes can be made without disrupting the other
elements in your application that you have reused. So without having to rewrite the
entire application, you can keep its functionality while making necessary changes.
Polymorphism
The root of polymorphism is a word that could easily replace it to describe the pro-
cess—metamorphosis. The term is from the Greekmetamorphoun, meaning to trans-
form. One definition describes metamorphosis as a magic-like transformation—
something a sorcerer would do. If you like, think of polymorphism as giving the pro-
grammer the power of a sorcerer.
Generating Polymorphism Using an Abstract Class
Another definition of polymorphism is that it allows formany(poly)forms(morph).
In Example 1-21 through Example 1-25, you saw how theabstractMethodhad more
than a single form. That’s polymorphism. To see it in a more practical application,
consider people’s taste in music and emerging forms of music. Suppose you create a
Example 1-25. ImplementSubChange.as
package
{
//ImplementSubChange of Abstract class
import flash.display.Sprite;
public class ImplementSubChange extends Sprite
{
private var doDemo:AbstractClass;
public function ImplementSubChange( )
{
doDemo=new SubclassChange( );
doDemo.abstractMethod( );
doDemo.concreteMethod( );
}
}
}