当前位置: 动力学知识库 > 问答 > 编程问答 >

naming conventions - In the Command pattern what do you call a command that groups together other commands?

问题描述:

This should be easy,

I am trying to come up with the name for a command class that is a collection of other commands. All the sub commands will be run, when the master command is run.

Any ideals?

网友答案:

CompositeCommand, maybe?

网友答案:

Composite Command?

网友答案:

For what it's worth, the Head First book from O'Reilly about design patterns calls it a MacroCommand.

网友答案:

"Batch Command" would be my choice.

网友答案:

If you are simply creating a base class that will automatically execute a list of commands, and is meant to be used as is (i.e. just create a generic Command and pass in a list of sub commands) then I'd use something like CompositeCommand or BatchCommand. If this is not meant to be a generic class but rather a hard-coded specific implementation I'd name it after what the overall operation is. For example:

BatchCommand registerCmd = new BatchCommand();
registerCmd.add(new CreateProfileCmd());
registerCmd.add(new CreatePreferences());
registerCmd.add(new SendWelcomeEmailCmd());

vs

class RegisterCmd extends Command {
  execute() {
    new CreateProfileCmd().execute();
    new CreatePreferences().execute();
    new SendWelcomeEmailCmd().execute();
  }
}

In the second case I wouldn't create a new name for the RegisterCmd class. It's just a command that happens to call other commands to do its job.

网友答案:

Could use "Script" as another alternative suffix (but I'd probably go with CompositeCommand)

网友答案:

I liked BatchCommand, it represents what it is. I think that CompositeCommand is very "pattern", just as prefixing with "Singleton" a class that is supposed to have only one instance.

分享给朋友:
您可能感兴趣的文章:
随机阅读: