< Day Day Up > |
Many OOP designs require the use of a so-called abstract class . An abstract class is any class that defines one or more abstract methods ” methods that have a signature and a return type but no implementation (i.e., no code in the method body). A class that wishes to extend an abstract class must implement all of the superclass's abstract methods; otherwise , a compile-time error occurs. All subclasses of an abstract class effectively promise to provide some real code to do a job the abstract class only describes in theory. Abstract classes are a common, important part of polymorphic designs. For example, in our earlier discussion of polymorphism, we studied a Shape class with Circle , Rectangle , and Triangle subclasses. Traditionally, the Shape class's draw( ) method would be defined as an abstract method, guaranteeing that:
Unfortunately, ActionScript 2.0 does not yet support abstract classes or abstract methods. Instead of defining an abstract method in ActionScript, we simply define a method with no code in its body. It's left up to the programmer (not the compiler) to ensure that the subclasses of a would-be abstract class implement the appropriate method(s). In contrast to an abstract method , which must be implemented by a subclass, a final method is a method that must not be implemented by a subclass; otherwise, a compile-time error occurs. Final methods are used to prevent programmers from creating subclasses that accidentally introduce problems into the behavior of a superclass or intentionally sabotage a superclass. Like abstract methods, this useful OOP feature is not part of ActionScript 2.0 for Flash Player 7, but may be implemented in the future. |
< Day Day Up > |