
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
192
|
Chapter 6: Inheritance
we’re invoking A’s version of the method, so the output is:
Hello there
Finally, we have what we wanted. Each class method displays the class property
defined within its class.
The moral of the story is “Always qualify your static member references.”
Hopefully this little journey through the bramble will help us avoid similar thorns in
our code.
Best Practices for Overriding
So far, our consideration of overriding in ActionScript 2.0 has been limited to “like
members.” That is, we’ve seen how an instance method can override another
instance method or how a class property can override another class property. But we
haven’t discussed what happens when, say, an instance property overrides a class
method. We’ve specifically avoided this topic, because even though ActionScript 2.0
allows a property to override a method, doing so is atrocious OOP form.
In fact, ActionScript does not prevent any kind of overriding. If a member in a sub-
class has the same name as a member in its superclass, the subclass’s version over-
rides the superclass version. If the two members are both methods, they can have any
number of parameters, any types of parameters, any return type, or any access level
(public or private). If one member is a class member, the other can be an instance ...