Java Reference
In-Depth Information
}
}
Interfaces can be used to declare a type for an object. Any object that is declared to
have an interface type must adhere to all the implementations declared in the interface,
unless a default implementation exists. For instance, the following variable declaration
defines an object that contains all the properties that are declared within the
TeamType interface:
TeamType team;
Interfaces can also implement other interfaces (thus the same type of theory that is
provided by multiple inheritance). However, because no method implementation is
present in an interface, it is much safer to implement multiple interfaces in a Java class
than it is to extend multiple classes in C++.
Interfaces are some of the single most important constructs of the Java language.
They provide the interfaces between the user and the class implementations. Although
it is possible to create entire applications without using interfaces, they help to promote
object orientation and hide method implementations from other classes.
5-7. Modifying Interfaces without Break-
ing Existing Code
Problem
You've got a utility class that implements an interface, and many different classes with-
in the utility library implement that interface. Suppose that you want to add a new
method to the utility class and make it available for use for other classes via its inter-
face. However, if you change the interface, it will break existing classes that already
implement that interface.
Solution
Search WWH ::




Custom Search