Interfaces can be used be used for many things. The most commons uses are polymorphism and dependency injection, where you can change the dependencies at run time. For example, suppose you have an Interface called Database which has one method called getField(...).
public interface Database
{
public void getField(String field);
}
Now suppose you have use two databases in your application depending on your client: MySQL and PostgreSQL. You will have two concrete classes:
public class MySQL implements Database
{
// mysql connection specific code
@Override
public void getField(String field)
{
// retrieve value from MySQL
}
}
And...
public class PostgreSQL implements Database
{
// postgre connection specific code
@Override
public String getField(String field)
{
// retrieve value from Postgre
}
}
Now depending on your client preference, you can instantiate a MySQL or PostgreSQL class in your main
public static void main(String args[])
{
if (args[2].equals("mysql"))
Database db = new MySQL();
else
Database db = new PostgreSQL();
}
//now get the field
String foo = db.getField();
Or you can use Factory/Abstract Factory or scripting engine with JS or Ruby.