Interface and Implements Constructs

 <  Day Day Up  >  

Interfaces are a compile-time functionality that enable the developer to specify certain methods that every class that implements the interface must have. Interfaces cannot contain properties, static methods, or private methods . Interfaces must be defined within their own package ActionScript file. Multiple inheritance can be simulated with interafaces as classes can implement more than one interface. Any class that uses the implements keyword to extend the iproduct interface will require a getName and a getID method.

 interface iProduct {     function getName():String;     function getID():Number; } 

Every class that implements this interface must have at least two methods entitled getName() and getID() , as in the following example:

 class Product implements iProduct {           function getName():String {return name};           function getID() :Number {return id}; } 

The following example would return a "class must implement interface methods" error because no getID() method is defined:

 class Product implements iProduct {     function getName():String {return name}; } 

Objects in ActionScript 2.0 can implement multiple interfaces; however, they are limited to inheriting from only one class. This is the main advantage of interfaces over class inheritance.

 <  Day Day Up  >  


Object-Oriented Programming with ActionScript 2.0
Object-Oriented Programming with ActionScript 2.0
ISBN: 0735713804
EAN: 2147483647
Year: 2004
Pages: 162

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