Interfaces provide specifications not only for you, but also for all implementers who use them.
For example, suppose that you have completed your movie application, and it
works fine. Some time later, another programmer claims to have a
definition of the Movie
class that is somehow better, perhaps
because its methods compute faster. Further, the other programmer claims
that his Movie
class can be dropped into your application,
substituting for your Movie
class, with no other changes to your
application.
Naturally, you would like to be able to use the other Movie
definition without fear. Also, you would not want to require the other
programmer to implement his Movie
class in any particular way,
because that might handicap his creativity or force rework.
Fortunately, if you have defined the specification-retaining
RatingInterface
interface, and the other programmer's Movie
class implements that interface, you can be sure that his class does, in
fact, have a rating
method that has return type and
argument types the same as those of your rating
method.
Thus, RatingInterface
is a specification not only for you, but also
for all implementers who which to define Movie
classes.