Java Reference
In-Depth Information
Drawable identifiesatypethatspecifieswhattodo(drawsomething)butnothow
to do it. It leaves implementation details to classes that implement this interface. In-
stancesofsuchclassesareknownas drawables becausetheyknowhowtodrawthem-
Note An interface that declares no members is known as a marker interface or a
tagging interface . It associates metadata with a class. For example, the Cloneable
marker/tagging interface states that instances of its implementing class can be shal-
interface.Forexample,when Object 's clone() methoddetects,viaRTTI,thatthe
calling instance's class implements Cloneable , it shallowly clones the object.
Implementing Interfaces
By itself, an interface is useless. To be of any benefit to an application, the interface
needstobeimplementedbyaclass.Javaprovidesthe implements reservedwordfor
this task. Listing 2-43 demonstrates using implements to implement the aforemen-
tioned Drawable interface.
Listing 2-43. Implementing the Drawable interface
class Point implements Drawable
private int x, y;
Point(int x, int y)
this.x = x;
this.y = y;
int getX()
return x;
int getY()
return y;
Search WWH ::

Custom Search