|
This pattern serves a basic functionality for branches in a method call. Depending on a condition one of two named methods is called.
Branches often occur in a software system: depending on a condition one of two ways has to be selected. This can either be a simple or very complex condition.
This pattern is applicable in simple cases only. For more complex situations it seems useful to either derive from or aggregate it.
Optional, for testing on variable elements a single parameter can be given on binding. Of course, the test on the parameter element has to know what elements it accesses to.
If no parameter is given, the branch method will not accept parameters.

The target object should understand the methods given with methodOnTrue and methodOnFalse .
The macro optionalParameter will be replaced depending on the existence of a parameter. Either it will be replaced following optional Parameter-Template or it will simply be removed.
({condition}) ifTrue: [ ^self {methodOnTrue}{optionalParameter}] ifFalse: [ ^self {methodOnFalse}{optionalParameter}].
: {parameter}
Pattern MethodBranch Category redirection ObjectType use target Expression implement optional parameter SingleMethod implement branch SingleMethod use optional methodOnTrue SingleMethod use optional methodOnFalse Expression implement condition End