I have some SQLite Databases and i have 3 classes for the main handling.
1. A base SQLiteDatabase Class for the Connection
public class SQLiteDatabase
{
public SQLiteDatabase(string databasePath);
public void OpenConnection();
public void CloseConnection();
protected DataReader ExecuteReader(string sql);
protected void ExecuteNonQuery(string sql);
}
2. A Class for handling the Tables like create a table.
public class SQLiteDatabaseTableHandler: SQLiteDatabase
{
public SQLiteDatabaseTableHandler(string databasePath)
: base(databasePath)
{
}
public void CreateTable(IDatabaseTable table) { }
public void UpdateTableCompatibility(IDatabaseTable table) { }
}
3. My application specified Database class for getting some stuff from the own Database.
public class ConcreteSQLiteDatabase : SQLiteDatabase
{
public ConcreteSQLiteDatabase(string databasePath)
: base(databasePath)
{
}
public SQLiteDataReader GetSpecifiedStuff(string id)
{
ExecuteReader("SELECT * FROM specified_table");
}
public SQLiteDataReader GetOtherSpecifiedStuff(string id)
{
ExecuteReader("SELECT * FROM other_specified_table");
}
}
In my ConcreteSQLiteDatabase class i need methods from the SQLiteDatabaseTableHandler. There are 2 ways to make it possible:
1. Inheritance
I can use a Inheritance in my ConcreteSQLiteDatabase from the SQLiteDatabaseTableHandler instead of SQLiteDatabase.
Like this
public class ConcreteSQLiteDatabase : SQLiteDatabaseTableHandler
instead of
public class ConcreteSQLiteDatabase : SQLiteDatabase
2. Association
My ConcreteSQLiteDatabase class could have a instance of a SQLiteDatabaseTableHandler, so i can use the methods from the instance.
Like this
public class ConcreteSQLiteDatabase : SQLiteDatabase
{
public SQLiteDatabaseTableHandler TableHandler{get;set;}
public ConcreteSQLiteDatabase(string databasePath)
: base(databasePath)
{
TableHandler = new SQLiteDatabaseTableHandler( databasePath );
}
}
I don't know which way should i use in this case, Association or Inheritance?
Sorry for my bad english...