|
Generic way to load resources
Hi,
I am currently developping a program that uses files to store data. There
are different sorts of data: preferences about the program, high scores
(it 's a game) and document data (the main data of the program - a
game-map in this case).
My problem is the following: how do I create an object-structure to load
data from files in a flexible way? With flexible I mean:
- When I change the file-format, I need to hack in as less classes as possible.
- When I migrate from files to a database in the future, it must be easy in my
design.
- When I add extra data in a later version of the program, or support different
file formats for the data, it must also be possible.
I tought that the 'abstract factory pattern' could be a solution for my
problem. I make an 'abstractdatafactory' object and for each data-format a
'concretefactory'. Each 'concrete factory' will implement the abstract
method 'loadData(file : String) : Data' of the 'abstract factory'. Is this
a good way to load data? And is it also permitted to put the 'save part'
in the factory classes?
Has sombody proposals to solve this problem? Any kind of tips or tricks
are appreciated.
Greetz,
Jan Meskens
Student Computer Science
|