wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes when to use interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "when to use interface" Watch "when to use interface" New topic
Author

when to use interface

ahamed irshad
Ranch Hand

Joined: Feb 26, 2010
Posts: 31

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

You can do anything, but not everything
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
GeeCON Prague 2014
 
subject: when to use interface