Interfaces are useful when you know WHAT something should do, but not HOW is should do it. They are used to create a standard programming interface for a particular task on a variety of objects. For example, the Comparable interface in Java defines a single method - compareTo. We know if we want to compare two objects we need a compareTo method. But, we can't know how to compare all possible objects! So, the Java designers created the comparable interface the defined the API for comparing, specifically the compareTo method. Now anyone who designes a class can allow anyone else to compare different objects of that class by implementing the Comparable interface. When we implement an interface, we are required to provide method bodies (the working code) for all methods defined in the interface. Therefore, if I design a class and I want others to be able to compare objects of my class, I have my class implement the comparable interface and I provide the details on how to compare two of my objects and determine if one if greater than, less than, or equal to another. For the user of classes, implementing interfaces guarantees that my class supports the methods defined in the interface. You can think of interfaces as contracts. If I implement an interface, I guarantee that my class will contain the methods in the interface, and you guarantee that you will call the methods based on the details outlined in the interface. Does this help?
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
"Firstman Lastman", Welcome to JavaRanch. We don't have many rules here, but one we do have is a naming policy. Please edit your display name to comply with this policy. Thank you in advance for your cooperation, and we look forward to seeing you around the Ranch. [ October 26, 2003: Message edited by: Jason Menard ]