Hi all :)
I've been designing a database access layer that allows us to support multiple databases in our programs. In the end, the users of our programs shall be able to choose the underlying database system from a range of database systems. Some small clients might be happy with MS Access, others prefer MySql, others DB2. Those db systems are the ones I want to target for now.
Given those requirements, I've come up with an abstract class DatabaseConnection. Internally, I use the System.Data.Common.Data.DbConnection-class, which already gives me quite some flexibility.
The things that need concrete instances (OleDbCommand instead of DbCommand e.g.) are hidden in abstract methods like CreateDbCommand(). Subclasses (like AccessDbConnection) implement those and provide the concrete instances. Currently that leads to this hierarchy (class names abbreviated for readability):
DatabaseConnection / | \ AccessConn MySqlConn DB2Conn
However, there are a few operations that are specific to the underlying database system, such as retrieving all table names. It feels wrong to place an abstract method GetTableNames() into the DatabaseConnection-class and have the subclasses overwrite it.
I thought maybe I can create another abstract base class called DatabaseTools, declare those operations there and then implement them in subclasses that resemble the subclasses of the DatabaseConnection class. Which means that for a AccessDbConnection, I'd also have a class AccessTools etc etc:
DatabaseConnection DatabaseTools / | \ / | \ AccessConn MySqlConn DB2Conn AccessTools MySqlTools DB2Tools
Somehow I'm not really thrilled by this idea.
What ideas do you have to solve this design problem?
Thanks in advance for your time and answers :)
Cheers
Christian