My take is that what we’re talking about here is a “poor man’s” component architecture implementation regardless of storing by strings or objects.
It ignores the main benefit of Java which is the Class / type system. I’ve gone down the full component architecture implementation path with TyphonRT.
A simplified / reduced example from the API:
public final <T extends IComponent> T getAs(@Nonnull Class<T> componentType) { ... }
public final <T extends IComponent> boolean set(@Nonnull Class<T> componentType, @Nonnull T component) { ... }
// Basic usage
entity.set(Stuff.class, new Stuff());
Stuff stuff = entity.getAs(Stuff.class);
The nice thing about using the type system to your advantage is that it allows type safety for setting and getting objects / components out of the container. In my efforts I also allow storage in a List by type and retrieving a protected iterator by type.
The big trouble spot for all Java entity systems / component architectures is the trick of storing multiple single components or collections by the same type. I’ve overcome that by some really fancy extensible enum tricks and generic method signatures for the component architecture API.
You can do:
// LEFT_ENGINE, RIGHT_ENGINE come from an extensible enum let's say `Engines` and statically imported.
entity.set(LEFT_ENGINE, new Engine());
entity.set(RIGHT_ENGINE, new Engine());
Engine engineLeft = entity.getAs(LEFT_ENGINE);
Engine engineRight = entity.getAs(RIGHT_ENGINE);
So, in short for the OP. What you are doing is a pseudo solution and one that ignores the biggest benefit of Java which is the type system. I’d say take a look at the various entity system implementations out there. They are adequate, but not as far as things can actually be taken.
For now check out:
One day I’ll release the beast / TyphonRT… :