I have this problem:
In C #, I create a program that needs to connect to various databases (SQLite, SQL Server Compact, MS Access, etc.). I set the parameter called "dbType" in app.config (it can be 1 for SQLlite, 2 for SQL Server Compact, 3 for MS Access, etc.). This parameter must be changed by the user while the program is running with a drop-down menu or something like this.
Then the program reads this parameter and creates an instance of the database interface implementation (database), which corresponds to the selected database.
The code:
class ObjectDatabaseCreator
{
protected ObjectDatabase objectDb;
protected Object objectDAO;
protected int dbType;
protected String dbName;
public ObjectDatabaseCreator()
{
}
public ObjectDatabaseCreator(String dbName)
{
this.dbType = ObjectConfiguration.getDbType();
this.dbName = dbName;
}
public ObjectDatabase getObjectDatabase()
{
switch (dbType)
{
case 1:
objectDb = new ObjectDatabase(new Database_Impl_1(dbName));
break;
case 2:
objectDb = new ObjectDatabase(new Database_Impl_2(dbName));
break;
case 3:
objectDb = new ObjectDatabase(new Database_Impl_3(dbName));
break;
case 4:
objectDb = new ObjectDatabase(new Database_Impl_4(dbName));
break;
}
return objectDb;
}
}
Well, it looks like it works, but I would like to know if it is possible to simplify adding other databases, I mean, if there is another db, I have to change this class, recompile, etc.
BLL, , Person, Customer ..? , .
,