6.9 Abstract and Final Classes Not Supported

 <  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:

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

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

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  >  


Essential ActionScript 2.0
Essential ActionScript 2.0
ISBN: 0596006527
EAN: 2147483647
Year: 2004
Pages: 177
Authors: Colin Moock

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net