mercredi 21 octobre 2015

Is this an established design pattern?

I am writing a game in Java, in which each Entity can have a list of attached EntityComponents. For example, Entities that can be killed (such as the Player) will have a Health component. Checking the Player's health looks like this:

int health = player.getComponent(Health.KEY).getHealth();

I came up with a slight shortcut, where every EntityComponent contains a static get method that calls an Entity's getComponent method with the appropriate key. Checking the Player's health now looks like this:

int health = Health.get(player).getHealth();

Is this an established design pattern? If so, which is it? Does it seem like a good idea (essentially an added method call for slightly shorter code)? Is there, perhaps, a better way to achieve what I'm trying to do?

Aucun commentaire:

Enregistrer un commentaire