Programming to an Interface
Charles W. Kann · Auerbach Publications eBooks · 2017
This chapter introduces the concept of a Java interface. An interface in Java is a definition of behavior to be implemented by objects. Once an interface is defined, components can then be written to take advantage of the behavior promised in the interface. These components can then be reused, as they work with any object that implements the behavior of the interface. This is a type of reuse that we will call generic reuse .* Note that an interface is not a data type, which is a collection of data values and operations on those values. An interface is simply a definition of behavior an object must implement to work correctly with an algorithm, collection class, or component. However, like a data type, an interface is checked at compile time to ensure that the objects are valid to be used with the component.