• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Interface and implementation

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain the terms interface and implementation. I am
really confused about these.
Thanks,
Binod.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Binod,
I think I know how to explain the difference. Hopefully if I've got it wrong others will jump in with corrections .
An interface guarantees specific behaviour for an object. The implementation is how that behaviour is achieved.
For example, suppose you were writing a program that handled various household appliances: TV, stove, radio. All of these objects have On/Off switches so you know you want each object to provide On/Off behaviour. Exactly how each appliance turns itself from Off to On (the implementation) differs. (At least I think it does, an electrician may disagree ).
To guarantee On/Off behaviour for all electrical appliances you could define an Interface OnOff:

Then build your class structure:

In essence, if a class implements an Interface, it guarantees that the behaviour defined by the interface will be available in the class. The interface defines what will happen, the actual implementing class has to provide the steps for how it will happen.
Hope that helps.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
excellent analogy, Jane...

Ramani.
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ramani
 
Binod
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Jane. It was really helpful.
Binod.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic