I don't claim to be a design guru, nor do I claim to be a C++ expert, this is just me working idea through to try and come up with a decent and comprehensive resource manager.
With that out of the way, welcome [smile]
As started above and before now, this is basically going to be me pondering things and working through a design of a resource system, hopefull I'll formalise this when finished and both this and the formal document will be some use to people.
Anyways, right now I've finished and coded up the first design; its a simple two class affair, one being the manager and the other being a 'handle' class.
One of the first issues which hit me was; is manager a good name?
After a trip to dictionary.com I decided it was and the definition helpped work out one other implimentation detail; what responciblity goes where?
Manager at Dictionary.com
someone who controls resources and expenditures
Using this quote and thinking about it in real world terms means that really all a manager should do is hand out and keep a track of resources, this is important as it lets us know where we should put the functionality such as binding the texture.
Why is this important? Well, the definition gives us the 'scope' of the class and its responibilties and one of the tenets of OOP is the Single responsibility principle or SRP, which states that one class should have one responciblity, which in this case is the handing out and tracking of resources, so to add things such as binding to it would be a violation of the SRP.
This means the handle object needs functions so that we can act upon a texture, I'm reasonably happy with this idea, although the SRP is kinda cominbg back to me at this point as does a handle really need to act on a texture at all? Maybe someone else should be doing this work and is supplied a handle? hmmm, worth considering, if only because as things stand the handle would have to free the texture, does this make sense wrt SRP?
The net result of this is the following code, which as it stands it technically a very basic texture resource handler;
handle_t TextureManager::LoadTexture(const std::string &filename)
texturemap_t::iterator it = texturemap.find(filename);
if(it != texturemap.end())
handle_t texture(new TextureHandle(id));
if(img->getFormat() == GameTextureLoader::FORMAT_RGBA)
TextureManagerLib v0.1 is done [smile]
Now, to consider the issues I raised some more...