|
|
|
|
So, What is an Interface? An interface has the following properties:
Basically, and interface is similar to an abstract class that contains:
Interfaces allow you to "add in" multiple behaviors for a class. If you want to instantiate such a class, that class must implement all the abstract methods from all the interfaces it has said it implements. If that class does not implement the abstract methods from its interfaces, then that class is abstract. The ability for a class to implement a number of interfaces amounts to multiple interface inheritance. Java's more restricted form of multiple inheritance is a much safer form than the more general multiple inheritance supported by C++. The trickiest area of multiple inheritance is when you are trying to inherit multiple implementations; if you restrict multiple inheritance to multiple interface inheritance, most of the problems go away. Interface "Contracts"One way to look at an interface is to consider it to be a "contract". Any class that specifies it implements that interface is "contractually obligated" to implement all the (abstract) methods specified in the interface. Such a "contract" only specifies that there be an implementation, not how it might be implemented.
|
|
This page was last modified on 02 October, 2007 |