MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 47

Actionscript language reference
Table of Contents

Advertisement

Interfaces
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. As with Java, ActionScript 2.0 does not allow a class to extend multiple
classes directly but does allow a class to extend a single class and implement multiple interfaces.
So, 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.
Unlike Java interfaces, ActionScript interfaces exist at runtime, which allows type casting. For
more information, see
Encapsulation
In elegant object-oriented design, objects are seen as "black boxes" that contain, or encapsulate,
functionality. A programmer should be able to interact with an object by knowing only its
properties, methods, and events (its programming interface), without knowing the details of its
implementation. This approach enables programmers to think at higher levels of abstraction and
provides an organizing framework for building complex systems.
Encapsulation is why ActionScript 2.0 includes, for example, member access control, so details of
the implementation can be made private and invisible to code outside an object. The code outside
the object is forced to interact with the object's programming interface rather than with the
implementation details. This approach provides some important benefits; for example, it lets the
creator of the object change the object's implementation without requiring any changes to code
outside of the object, as long as the programming interface doesn't change.
Polymorphism
Object-oriented programming lets you express differences between individual classes using a
technique called polymorphism, by which classes can override methods of their superclasses and
define specialized implementations of those methods.
"Creating an interface" on page
58.
Principles of object-oriented programming
47

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

This manual is also suitable for:

Flex

Table of Contents