I'm writing an application that is used to catalog files, and attribute those files with meta data. A photo album program would be a good comparison to what I'm trying to do.
I'm trying to abstract the interface between my program and the file system which stores the files, and the database which stores the meta data for the files. This is to allow for mocking and unit testing. In addition, I'd like to be able to create multiple implementations of my tool that can leverage different database formats, and or file system structures.
For example I've created an interface, IFileSystemAdaptor
, which is used to read and write files and associated metafiles (thumbnails and attachments) to a file system. Actual implementations of IFileSystemAdaptor
decide where files are stored and in what structure.
public interface IFileSystemAdaptor
{
void WriteFileData(string fileName, Stream data);
Stream ReadFileData(string filename);
void DeleteFileData(string filename);
void ClearAllData();
void WriteMetaFileData(string filename, string path, Stream data);
Stream ReadMetaFileData(string filename, string path, Stream data);
void DeleteMetaFileData(string filename, string path);
void ClearMetaFilesData(string filename);
}
So now I'm trying to do something similar with the connection to the database. I have a fairly complex structure of classes which I want to read and write to and from a database. I'd like to be able to have implementations that connect to a SQL Server database, and another implementation that uses a serverless database such as SQL Lite.
How can I abstract the data access layer between my classes and the database in a way which will support multiple database types? Also how can I allow for inheritance relationships in my classes to be reflected in the database? I'd prefer a database format following the "class table inheritance" pattern (See one of my previous questions).