API clutter - incorrect abstraction. Round peg and square hole.
Why does model need to know about file system?
Why does it need to know about texture manager?
A model is in-memory representation of some data. It doesn't know or care about file system, texture managers or anything else.
The method of loading something from disk (or other source) is known as serialization. Let's say that model is serializable (and we only support reading).
class Model { void load(Source &);};
Source is something that can read bytes, but implemented elsewhere and completely independent.
Quote:filesystemManager
Apparently, something that manages a file system. So how do we make a model from file system?
Model loadModelFromFile(string s) { Source s = filesystemManager.getSource(s); Model m = new Model(); m.load(s); return m;};
But how does loadModelFromFile know where to get filesystemManager? And, how will model resolve textures?
Who really needs to know how to resolve textures? The Source, which will deserialize some opaque reference into live texture. But this means that file manager can no longer provide us with Source, but we must construct a specific one for model loading:
Model loadModelFromFile(string s) { File f = filesystemManager.getFile(s); Source s = new ModelLoaderSource(f, materialManager); Model m = new Model(); m.load(s); return m;};
This is better, loading is now done. ModelLoaderSource implements Source interface, it takes reference to file from which to read (can be FileSource<-Source) and material manager which will resolve serialized references into loaded textures.
But, both filesystemManager and materialManager are now just assumed to exist. Another problem is, that if materialManager gets asked for a texture it doesn't have, it needs to load it from filesystemManager.
class Assets { FileSystemManager filesystemManager; MaterialManager materialManager; Assets() { filesystemManager = new FileSystemManager(); materialManager = new MaterialManager(filesystemManager); } Model loadModelFromFile(string s) { // implemented above }};
And voila, the spaghetti are untangled.
To load a model, you call your Asset class instance, and use loadModelFromFile utility method.