Two Phase Composite OperationIf you have an operation that has a validation phase and a execution phase, you can write it as:
Leaf>>operation
self validate ifTrue: [self execute]
When you use CompositePattern, the simplest implementation is to distribute the operation to the children:
Branch>>operation
children do: [:each ¦ each operation]
The problem is when execute modifies state in one child, and validate fails in a later child. Therefore, you should make validate and execute the composite operations, and push operation up to a common superclass:
Branch>>validate
^children conform: [:each ¦ each validate]
Branch>>execute
children do: [:each ¦ each execute]
This pattern was first expressed by RobBrown?
EditText of this page
(last edited April 16, 1999)
or FindPage with title or text search