[Fling] Using composite pattern to handle the AssetManager

Chris Allen mrchrisallen at gmail.com
Wed May 24 16:55:38 EDT 2006


Hi Guys,

I was just chatting with Simon about the AssetManager and he asked why
we weren't using a more flexible structure for this implementation. I
asked him what he was thinking and this is basically what he suggested
in a nutshell.

Why not use the composite pattern for this?
http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/composite.htm

Basically, AssetManager and AssetLoader are doing much of the same
things (we have a AssetManager that manages a batch of AssetLoaders,
which themselves load multiple assets), they are both managing batches
of things. They both have the complete, start, progress etc. events.

Now, let's say that an AssetLoader is a Leaf, and it loads only one
asset. Then we can have an AssetManager as a Composite, that handles
multiple AssetLoaders. Both the AssetManager and the AssetLoader would
share one common interface.

If the AssetManager uses a common interface, you can build a tree as
you need it. You can then actually say something like:
myAssetManager.addAssetLoader(new AssetManager(...)) because the
AssetManager is an AssetLoader that manages multiple leaf
AssetLoaders.

This is a recursive structure that would allow us to do multiple
levels of assets as we see fit.

My main concern with this approach is that it might make the API more
confusing to use, and quite simply might be overkill when we are
generally only concerned with three levels
AssetManager->AssetLoaders->Assets. However, it would be nice to have
a general interface or an abstract class for these two classes
regardless so that there is less duplication going on.

What are your thoughts on this composite approach?

-Chris



More information about the Fling mailing list