![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
Interfaces in object-oriented programming can be described as classes whose methods are not implemented (defined). Another class can implement the methods declared by the interface.
An interface can also be thought of as a "programming contract" that can be used to enforce relationships between otherwise unrelated classes. For example, suppose you are working with a team of programmers, each of whom is working on a different part (class) of the same application. While designing the application, you agree on a set of methods that the different classes will use to communicate. So you create an interface that declares these methods, their parameters, and their return types. Any class that implements this interface must provide definitions for those methods; otherwise, a compiler error will result.
You can also use interfaces to provide a limited form of "multiple inheritance," which is not allowed in ActionScript 2.0. In multiple inheritance, a class extends more than one class. For example, in C++ the Cat class could extend the Mammal class, as well as a Playful class, which has methods ChaseTail and EatCatNip. ActionScript 2.0, like Java, does not allow a class to extend multiple classes directly. However, you could create a Playful interface that declares the ChaseTail and EatCatNip methods. A Cat class, or any other class, could then implement this interface and provide definitions for those methods.
For more information, see Creating an interface.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |