Right now, I have an AssetLoader interface, which has one implementation per platform. There can only be one instance of it, because it has some state (e.g. the path to the APK on Android).

It has two methods (the game doesn't have sound):

  • Pixmap loadImage(String path)
  • Pixmap loadText(String text, String fontFamily, int fontSize)

While that works well enough in practice, I feel this is bad design. In particular, I have two issues with it:

  1. I have to duplicate image and font loading. It's not exactly the same code, because there are different methods used for loading from the file system and loading from a ZIP file, but I could certainly just load a font or an image into memory and return that.
  2. loadText does a bit much at the moment: It loads a font from the disk, renders each glyph of the text onto a pixmap and returns that. More unnecessary code duplication.

What do you think, is this as bad as I think it is? How would you address it?

I don't insist on having a single AssetLoader with one implementation per platform, so please don't hold your suggestion back because it would get rid of that. In fact, I'm not perfectly happy with the beast, but can't think of a nicer approach.

  • \$\begingroup\$ 1. Have you considered re-factoring duplicate code into private methods that both public methods can call? 2. Perhaps you can make this method easier to manage by consolidating each of its tasks into private methods for it to call. \$\endgroup\$
    – Gigggas
    Commented Jan 22, 2013 at 8:53


Browse other questions tagged .