M
M
Mikhail Konyukhov2013-02-08 18:39:17
Java
Mikhail Konyukhov, 2013-02-08 18:39:17

Interface and return type in Java. How to be?

There is a code:

public interface DfgDbAdaptee {
   public boolean checkTableExists(String tableName) throws DfgFatalException;
}

public class DfgDbSqliteAdapter implements DfgDbAdaptee {
   public boolean checkTableExists(String tableName) throws DfgFatalException
   {
    .....
   }
}

public class DfgDbFMDBAdapter implements DfgDbAdaptee {
   public boolean checkTableExists(String tableName) throws DfgFatalException
   {
    .....
   }   
}

public class DfgDb {
   public static ??? Factory()
   {
      int dbType = DfgAppConfig.getDbType();
      if (dbType == DfgAppConfig.DBTYPE_SQLITE){
             return new DfgDbSqliteAdapter;
      }else if (dbType == DfgAppConfig.DBTYPE_FMDB){
             return new DfgDbFMDBAdapter;
      }
      throw new DfgConfigException("Unknown db type in config");
   }
}

//и гдето в коде вызываем:
??? db = DfgDb.Factory();
db.checkTableExists(new String("lalala"));


Actually the question is how to describe the type that is shown in the code above as three questions? The bottom line is that the Factory must return any class that has an implementation of the DfgDbAdaptee interface.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyushov, 2013-02-08
@piromanlynx

Just write DfgDbAdaptee instead of questions. That's what interfaces are for.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question