«^»
10.2. Producing classes that conform to an interface

Instead, the purpose of Java's interface construct is to describe the interface to which a set of classes conform, i.e., each class implements the interface.

For example, there are several ways of providing a class for representing a date each of which stores the details of a date in a different way: we could use three ints representing a year, a month and a day; a short and two bytes representing a year, a month and a day; one int that stores the number of days since the beginning of time; and so on. So we could provide several classes, each one of which conforms to the DateIF interface.

We should document that a class implements an interface. This is done by means of an implements clause:

0769: import java.util. StringTokenizer;
0770: public class Date implements DateIF
0771: {
0772:    private int iYear;
0773:    ...
0774:    public String toString()
0775:    {
0776:       return iYear + "-" + iMonth/10 + iMonth%10 + "-" + iDay/10 + iDay%10;
0777:    }
0778: }

If Date says that it implements DateIF, then Date must at least include declarations for each method that is defined in DateIF.