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.
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.
Suppose we're creating a logging class, Logger, that reports status messages ("log entries") for a program as it runs. ...