1 |
An interface specifies a collection of methods (behaviors) without implementing their bodies (akin to giving the API).
-
public interface Storable {
-
public abstract void store(Stream s);
-
public abstract void retrieve(Stream s);
-
}
|
2 |
Any other class which implements the interface is guaranteeing that it will have the set of behaviors, and will give concrete bodies to the methods of the interface.
|
3 |
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.
|
4 |
Interfaces can be implemented by classes on unrelated inheritance trees, making it unnecessary to add methods to common superclass.
|