Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
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. – Gigggas Jan 22 at 8:53

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.