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

Chapter 9. Interfaces

An interface is an ActionScript language construct that defines a new datatype, much as a class defines a datatype. However, whereas a class both defines a datatype and provides the implementation for it, an interface defines a datatype in abstract terms only, and provides no implementation for that datatype. That is, a class doesn't just declare a bunch of methods and variables, it also supplies concrete behavior; the method bodies and variable values that make the class actually do something. An interface, instead of providing its own implementation, is adopted by one or more classes that agree to provide the implementation. Instances of a class that provides an implementation for an interface belong both to the class's datatype and to the datatype defined by the interface. As a member of multiple datatypes, the instances can then play multiple roles in an application.

Tip

Don't confuse the term interface, as discussed in this chapter, with other uses of the word. In this chapter, "interface" refers to an ActionScript language construct, not a graphical user interface (GUI) or the public API of a class, sometimes also called an interface in general object-oriented programming theory.

Unless you're familiar with interfaces already, theoretical descriptions of them can be hard to follow, so let's dive right into an example.

The Case for Interfaces

Suppose we're creating a logging class, Logger, that reports status messages ("log entries") for a program as it runs. ...

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