The ChainBuilder service implements the Gang of Four Chain of Command pattern.
The ChainBuilder is provided with:
- A command interface
- A list of commands that implements the command interface
- A toString value (to be returned by the chain in response to toString())
From this, the ChainBuilder creates a new chain implementation object. The chain object implements the command interface.
Invoking a method on the chain object will, in turn, re-invoke the same method, with the same parameters, on each command object.
If a command object returns a value that is not null, false or 0, then the chain terminates and returns that value. Command methods may take any number of parameters and may return any value type (including void).
Commands are free to throw a checked or unchecked exception; these are not caught by the chain.