• 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

when to use interface

 
Ranch Hand
Posts: 31
Opera C++ Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi to all,

i know the concept of interface.but i have no clear cut idea about when should i use interface.thanks in advance
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are many reasons why you might want to use an interface.

One example is to decouple "how a service looks" from the actual implementation, which allows you to have different implementations (that all "look the same" from the outside). A client program (that uses the service) is programmed against just the interface, so that different implementations can be plugged in at runtime. An example of this are JDBC drivers. In your program that uses JDBC, you just use the interfaces (for example Connection, Statement, and ResultSet). The JDBC driver implements those interfaces with classes that are for a specific database (for example Oracle or MySQL), but the client program doesn't need to know the actual implementation classes.
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic