O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Abstract Not Supported

Many object-oriented designs require the use of a so-called abstract class. An abstract class is any class that defines zero or more abstract methods--methods that have a name, parameters, and a return type but no implementation (i.e., no method body). A class that wishes to extend an abstract class must either implement all of the superclass's abstract methods, or be abstract itself; otherwise, a compile-time error occurs. 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:

  • Each Shape subclass provides a means of drawing itself to the screen.

  • External code can safely call draw( ) on any Shape subclass (because the compiler will not let a class extend Shape without implementing draw( )).

Unfortunately, ActionScript does not support abstract classes or abstract methods. Instead of defining an abstract method in ActionScript, you should simply define a method with no code in its body, and document the method as "abstract." 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 many cases, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required