An interfaces specifies a collection of methods without implementing their bodies.
-
public interface Storable {
-
public void store(Stream s);
-
public void retrieve(Stream s);
-
}
|
Interfaces are used to indicate that a class has a certain behavior (has certain methods) without conveying anything else about the class.
|
Interfaces solve some of the same problems as multiple inheritance, without as much overhead at runtime.
-
There is a small performance penalty because interfaces involve dynamic method binding.
|
Interfaces can be implemented by classes on unrelated inferitance trees, making it unnecessary to add methods to common superclass.
|