Pattern for loading and handling resources

Posted by Enoon on Programmers See other posts from Programmers or by Enoon
Published on 2012-12-15T10:31:22Z Indexed on 2012/12/15 11:21 UTC
Read the original article Hit count: 191

Filed under:
|

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

© Programmers or respective owner

Related posts about java

Related posts about design-patterns