Suppose that, besides Date we have also created other classes that implement the DateIF interface, e.g.:
0779: public class DateA implements DateIF { ... } 0780: public class DateB implements DateIF { ... }
If the code of some client needs to refer to a class (e.g., a parameter of some method is a date), then it should use the name of the interface (e.g., DateIF) rather than the name of a class (e.g., Date). For example:
0781: private static boolean iIsLeap(final DateIF pDateIF) { 0782: final int tYear = pDateIF.getYear(); 0783: return (tYear%400==0) || (tYear%4==0 && tYear%100!=0); 0784: }The only time when the code of a client needs to refer to one of the classes is when it wants to create a date. Then it has to choose which implementation to use, e.g., to choose between one of the following statements:
0785: DateIF tDateIF = new Date(); 0786: DateIF tDateIF = new DateA(); 0787: DateIF tDateIF = new DateB();The variable tDateIF is a reference variable that is of an interface type. It can refer to any object which is of a class that implements the interface.