Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed bad links due to copy-paste from cwiki-test

...

This is a useful pattern because it makes it very easy to extend a given process, simply by providing new commands and specifying where they fit into the overall process. Most often chain of command is combined with an ordered configuration to define what the list of commands are (and in what order they should execute).

...

Because this pattern is used so often inside Tapestry, a built-in service exists to create implementations of the pattern as needed. The ChainBuilder service takes care of all the work:

Code Block
java
languagejava
public interface ChainBuilder
{
  <T> T build(Class<T> commandInterface, List<T> commands);
}

...

This can be used inside a service builder method. Nothing says a service builder method just has to instantiate a class; it is only required to return an appropriate object. We can just let the ChainBuilder service create that object.

Code Block
java
languagejava
  public static MyChainService build(List<MyChainService> commands,
    @InjectService("ChainBuilder")
    ChainBuilder chainBuilder)
  {
     return chainBuilder.build(MyChainService.class, commands);
  }

...