• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Interfaces in Java

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have seen interfaces in many places.
EJB - Remote and Home
RMI - Remote Interface
CORBA Interface defnitions
Collections Interface
Interfaces can be used in place of classes as formal parameters and in the declaration of references
As far as defnition goes Interface is a contract that a class that
implements agrees to fullfill.
What i am looking for is a more general when-to scenarios, where you
can use interface?
Many times you use features of a language just because YOU want
to learn them or make your boss happy.
Can someone please throw some light on using interfaces properly.
Thanks,
Rajesh
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajesh Kumar:
I have seen interfaces in many places.
EJB - Remote and Home
RMI - Remote Interface
CORBA Interface defnitions
Collections Interface
Interfaces can be used in place of classes as formal parameters and in the declaration of references
As far as defnition goes Interface is a contract that a class that
implements agrees to fullfill.
What i am looking for is a more general when-to scenarios, where you
can use interface?
Many times you use features of a language just because YOU want
to learn them or make your boss happy.
Can someone please throw some light on using interfaces properly.
Thanks,
Rajesh


I don't know if this will help you, but here is my opinion:
With interfaces you define abstract features, different, not necessarily related classes can implement. So if a class does implement a interface it is not a kind-of relation. It is more a has-feature relation. So a good example are the listener interfaces of swing. If you want to define a window which should be able to react to pressing a button the window has to implement the corresponging listener interface . If you now look at the window you would say it is a window with the additional feature of listing to a button. You would not say it is a listener with the additional feature of being a window.
Hope this helps.
Stephan
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java Tutorial discusses interfaces and gives some examples as to when it is appropriate to use them.
[ October 29, 2003: Message edited by: Joe Ess ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interfaces are key to de-coupling classes and managing dependencies. To dig a little deeper into OO theory and practice, google for tutorials on Java and the "Open Closed Principle" or "Dependency Inversion Principle". Here's a little paper on DIP that I wrote. And mosey on down to the OO, UML, etc forum a ways down the page where people love to talk about this stuff.
 
author
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the Design Patterns book. First principles sez:

Code to the interface, not to the implementation.


Makes software "pluggable" (i.e. flexible). The best example I can point to is the "new" collections framework which is rife with interfaces.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic