• 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

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.
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic