Original Post
I'm working on implementing a file system object to handle file requests. There are three types of files that I might request: text files, data files, image files. Text files are simply text files and only store text that does not contain data, data files are key based lookup files (key value pair files or xml), and image files are read and converted to raw format (for now). I'm trying to create an object hierarchy for these files while providing interfaces to the users of the file system object. When working only with data files, my hierarchy was as follows: Key_Value_File->Data_File->File_Base->File File was the interface object returned by the file system, it contained the pure virtual functions for token reading, writing, creating, and deleting tokens plus some basic functions for getting filename and size and such. File_Base was the intermediary object that contains the filename and such and is what the file system object tracked and managed. Data file was an interface to all data files, providing pure virtual functions that were required to be implemented by all data files. Key_Value_File was the object that actually handled data retrieval from disk, putting it into a map, and implementing the token functions. Now that I'm trying to implement the other types of files, I'm running into an organizational issue. I can implement the text files and image files similar to how I have done the key value files, as follows: Image_File->File_Base->File Text_File->File_Base->File However, this means that the interface, File, would need to expose functions for reading text, reading data files, and reading image files. This is not really needed and introduces problems with the user trying to use the functions that don't belong to the top level object. Another idea I had was to implement separate interfaces off each type of file object, like so: Data_File ^ | Key_Value_File->File_Base->File Where Data_File and File are interfaces. However, if you just give the user the File interface object, they don't have access to the needed data retrieval methods. If you give the user the Data_File object they don't have access to methods provided in the File interface. I can also have Data_File be derived from File, however, this creates the diamond problem, which can be solved with virtual inheritance. Though, this makes proper order of destruction a little tricky. Another option is to eliminate File_Base, and replace it with the different file type's base object and just implement everything 3 fold and track all of them separately. Is there a better way than these three solutions? Each one has it's annoying drawbacks.