So lets say I have this interface:
public interface IBox
{
public void setSize(int size);
public int getSize();
public int getArea();
//...and so
A great example of how interfaces are used is in the Collections framework. If you write a function that takes a List
, then it doesn't matter if the user passes in a Vector
or an ArrayList
or a HashList
or whatever. And you can pass that List
to any function requiring a Collection
or Iterable
interface too.
This makes functions like Collections.sort(List list)
possible, regardless of how the List
is implemented.