Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I learned about the Command Design pattern and saw different implementations of it:


Receiver receiver = new Receiver();
Command command = new ConcreteCommand(receiver);
Invoker invoker = new Invoker();


Remote remote = new Remote();
DVDPlayCommand dvdPlayCommand = new DVDPlayCommand();

Probably, I missed something, but the second implementation seems less complicated and more clear from my point of view. First implementation calling chain: ExecuteCommand() calls to Execute() calls to Action() Second implementation calling chain: Invoke() calls to Execute()

Does the first implementation have advantages over the second?

share|improve this question

migrated from stackoverflow.com Dec 5 '12 at 13:46

This question came from our site for professional and enthusiast programmers.

Please, someone can help me? Maybe it was a bad idea move question here? –  zzfima Dec 17 '12 at 11:07
add comment

1 Answer 1

up vote 2 down vote accepted

First implementation is much better than the second one.

in first version you can have an array of commands in invoker class so you can execute all of them at one go.

whereas in second version of this functionality is not there. (psudeo code)

class Invoker{
    public List<ICommand> _commands;

Let me know if you need some working example too

share|improve this answer
add comment

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.