   Elegant design solution
  just looking to pick some brains here for an 'elegant' solution.problem:  A resource manager deals out serializable 'handles' to resources.  the handles themselves only store a string to the resource they refer to, and keep track of which resource manager they're associated w/ so that it can retrieve the resource.There are two seperate resource managers for static Images, and Animated Sprites.  I'm writing a tile-based map editor, for which I want tiles to be able to be represented by either Images, or Animated Sprites.  However in the tile class, storing a handle of each type, and enforcing checks to make sure only one is ever valid, doesn't seem like a clean or 'elegant' solution.I believe some form of abstraction is needed here, but I do not want to violate the rules of encapsulation.  I'm using Java, so any solution involving multiple inheritance will not work :(  any help?   
  Perhaps using a unified handle space with the msb-s of the handle representing the type and the lsb-s the index within that type. You can even use int-s for this. Then the resource manager can return the right object based on the handle. (this approach work in c, cpp, c# and java)Viktor   ;  Why do you need two handles in the first place? Can't a handle reference different resource managers, or are you telling us that the image resource manager is not the same type as the animated sprite resource manager?jfl.   ;Quote:Original post by DeusFacticiusThere are two seperate resource managers for static Images, and Animated Sprites.  I'm writing a tile-based map editor, for which I want tiles to be able to be represented by either Images, or Animated Sprites.  However in the tile class, storing a handle of each type, and enforcing checks to make sure only one is ever valid, doesn't seem like a clean or 'elegant' solution.I don't see the problem - your tiles just need to hold on to a Handle, which points at either an Image or an AnimatedImage.Possible problems:1. You've got separate classes for ImageHandle and AnimatedImageHandle (why?)2. You've got separate classes for ImageResourceManager and AnimatedImageResourceManager (why?)3. You don't have a single interface for Image and AnimatedImage. (make one!)You're going to have to clarify your actual setup and problem.   ;  Consider a normal image an animated image with only one frame, and your two heirarchys will collapse into one. :)   ;  well what made this problem even more complicted was the fact that i considered an animated sprite a set of animations, so if an object were to reference a sprite, they'd have to specify and animation from within that sprite as well.after reviewing my design, i think it would be best to refactor my sprite class into a simple animation chain class, as well as provide a single interface for both static and animated images.  thus the resource managers could be collapsed as well.thanks for the advice, to all.   