A Composite Command Chain
Posted by John Kleijn • Tuesday, May 27. 2008 • Category: PHPMy idea of fun is to combine existing patterns, producing a solution to more specialized problem than the original pattern specifications individually. I should probably get out more.
In this case, I was faced with the following problem: how to create a flexible, complex and multi-dimensional chain of Command Objects (a chain of commands and subcommands), that was executable top down over and over, without re-executing the same command twice for that chain. Operations should block the execution of their children on failure to complete. Children should be executed serial, and isolated from each others potential failure.
When faced with creating complex relations between objects of the same type, with operations to be executed on the underlying structure transparently, the Composite pattern can usually save the day. I created a mechanism to create a composite structure of any implementation of an abstract Command Object class.
Because I implemented Composite, I already had a mechanism to execute a Command and it's descendants in the order required.
»
