Pattern for loading and handling resources
- by Enoon
Many times there is the need to load external resources into the program, may they be graphics, audio samples or text strings.
Is there a patten for handling the loading and the handling of such resources?
For example: should I have a class that loads all the data and then call it everytime I need the data? As in:
GraphicsHandler.instance().loadAllData()
...//and then later:
draw(x,y, GraphicsHandler.instance().getData(WATER_IMAGE))
//or maybe
draw(x,y, GraphicsHandler.instance().WATER_IMAGE)
Or should I assign each resource to the class where it belongs?
As in (for example, in a game):
Graphics g = GraphicsLoader.load(CHAR01);
Character c = new Character(..., g);
...
c.draw();
Generally speaking which of these two is the more robust solution?
GraphicsHandler.instance().getData(WATER_IMAGE)
//or
GraphicsHandler.instance().WATER_IMAGE //a constant reference