
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
230
|
Chapter 8: Interfaces
Most other interfaces are named after the additional ability they describe. For exam-
ple, suppose an application contains a series of classes that represent visual objects.
Some of the objects can be repositioned; others cannot. In our design, objects that
can be repositioned must implement an interface named Moveable. Here is a theoret-
ical ProductIcon class that implements Moveable:
class ProductIcon implements Moveable {
public function getPosition ( ):Position {
}
public function setPosition (pos:Position):Void {
}
}
The interface name, Moveable, indicates the specific capability that the interface adds
to a class. An object might be a piece of clipart or a block of text, but if it imple-
ments Moveable, we know it can be repositioned. Other similar names might be
Storable, Killable,orSerializable. Some developers also preface interface names with
an I, as in IMoveable, IKillable, and ISerializable.
Interface Inheritance
As with classes, an interface can use the extends keyword to inherit from another
interface. For example, the following code shows an interface, IntA, that extends
another interface, IntB. In this setup, interface IntB is known as the subinterface, and
interface IntA is known as the superinterface.
interface IntA {
function methodA ( ):Void; ...