|
FollowRelationAndSum is a specialization of the Pattern FollowRelation . In contrast to it, the AndSum variant sums up all return values of the called remote operations. E.g., this way all the heatflows affecting a Room can easily be added simply by binding this Pattern to the Room objecttype and building the sum of all getHeatFlow -methods of the connected Walls and Radiators.
Each time when several other methods should be called one after the other and the return values of these methods should be added.. This Pattern can be aggregated by other Patterns as well.
This Pattern is a special form of FollowRelation and uses most of its funcionality.
bind: 'target' to: 'Room'; bind: 'operation' to: 'getHeatFlow'; bind: 'relation' to: '#(#LeftWalls #heatingOfRoom)'.
See section Motivation. The generated method in Smalltalk might look like this:
"compute sum over all relations." |sum| "init calculation" sum := 0. "1:n relation." self LeftWalls connections do: [ :anObject| sum := sum + anObject getHeatFlow ]. "1:1 relation." self controlOfRoom instance notNil ifTrue: [ sum := sum + self controlOfRoom instance getHeatFlow]. ^sum.
"compute sum over all relations." |sum| "init calculation" sum := 0. {loop} ^sum
See Pattern FollowRelation .
"1:1 relation." self {relation} instance notNil ifTrue: [ sum := sum + self {relation} instance {remoteOperation}{optionalParameter} ].
"1:n relation." self {relation} connections do: [ :anObject| sum := sum + anObject {remoteOperation}{optionalParameter} ].
If {parameter} is set, {optionalParameter} will be replaced with ': {parameter}', else it is replaced by an empty string.
Pattern FollowRelationAndSum Category indirection Description FollowRelationAndSum.html ObjectType use target ComplexRelation use relation SingleMethod implement operation Expression implement optional remoteOperation Expression implement optional parameter End