Java Reference
In-Depth Information
Figure 10.6
The MyPainter class uses the Paintable interface as a method parameter.
Figure 10.7
Output of the MyPainter program.
Using Interfaces
Interfaces have two equally important but different usages:
An interface can be used to expose the methods of a class, allowing
users of the class to interface with objects of the class via the methods in
the interface.
■■
An interface can be used to force certain behaviors on a class.
■■
These two usages create a wealth of design opportunities for Java applica-
tions. Being able to expose methods of a class using an interface is used exten-
sively in distributed computing, which includes technologies such as RMI
(Remote Method Invocation), CORBA, and Web Services.
Search WWH ::




Custom Search