• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

interface

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please can you briefly explain the concept behind interfaces?
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shanker
Have a read of this article. Does that help any?
Michael
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
shanker sothi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
Michael Fitzmaurice
Tom Blough
shanker.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am realy impress by the way this has been responded to especially Tom Blough Tom Blough You really cool.Thank you
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic