|
|
|||||
| Ultrashock Tutorials > Flash MX 2004 > ActionScript 2.0 | |||||
|
|||||
|
|
ActionScript 2.0 |
|
|||
09. Overriding, Overwriting or Overloading?It seems these terms cause some confusion among developers who are new to OOP. In ActionScript, we only have overriding and overwriting, but no overloading (two out of three ain't bad - Meat Loaf). Overriding means that a method or property steps in front of another and accepts the call. In the Math2.max() example, the new max() method overrides the original one in Math.max() (but uses it internally). Usually, overriding works with more than one class, with the subclass method or property overriding the superclass's method or property. This is also a form of polymorphism, meaning that there is more than one form (implementation) of a method. (Basically, having the same method name do different things.) Overwriting is different in that the original no longer exists -- it is written over by (replaced with) another file, class, method, or property. In the TestClass example above, this block of code overwrites/replaces the method in the instance: w.method = function() {
trace("New method");
};
Overloading (which is not a native feature of ActionScript) is another form
of polymorphism. It usually refers to the ability to handle different types
of data, or number of data, or operators working differently depending on
the meaning of the data. The most common overloading use in ActionScript
is a method with different number of parameters. Although not perfect, this
can be handled by a switch statement used with the arguments and arguments.length
properties.
|
|||||
©2003 Ultrashock.com - All rights reserved |