I just started reading a book called "Game Programming Patterns". In the very beginning, a simple pattern called the command pattern was explained, and the example for it was to be able to configure the action that specific keys trigger. But, actually, I have a question on that. Why would you use Commands to trigger those actions instead of just doing something like:
Map<Key, Action> map
if(isPressed(key)) map.get(key).trigger()
The result would be the same, and frankly, it seems a bit more effective in my mind. Could anyone please explain to me why, in that situation, you would use the command pattern instead of my example above?
Command Pattern Example:
Command* this_specific_key_command;
if(isPressed(key)) this_specific_key_command.trigger()
Where the command class is something like
class Command{
virtual void trigger() = 0;
}
Sorry for the messed up code. I hope it is understandable.
Aucun commentaire:
Enregistrer un commentaire