February 26, 2008 at 10:58 AM
Uses of Interface
Interfaces encodes similar types of classes that shares various resources but do not necessarily constitute a class relationship. For example, a human and a parrot both can whistle, it doesn?t mean that we should kept Humans and Parrots as subclasses of a Whistler class, rather they would most likely be subclasses of an Animal class (likely with intermediate classes), but would both implement the Whistler interface.
Interfaces can also be used to use an object without knowing its type of class, but rather only that it implements a certain interface. For example, if one were annoyed by a whistling noise, while another may not know whether it is a human or a parrot all that could be determined is that a whistler is whistling. Calling whistler.whistle() calls the implemented method whistle of object whistler no matter what class it has, provided it implements Whistler.]