Question

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?

Was it helpful?

Solution

CompositeCommand, maybe?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top