AG VLSI Design and Architecture

SFB 501 - Project D1: Application System "Buildings"

PSiGene

Pattern Catalog

[PSiGene]

4.2 Pattern FollowRelationAndSum

Intent

Sum up values delivered by connected objects.

Also Known As

Motivation

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.

Applicability

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.

Structure

.

Participants

Objects
Methods
Interfaces
Relations
Expressions

Collaborations

This Pattern is a special form of FollowRelation and uses most of its funcionality.

Consequences

Example:

FollowRelationAndSum
    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:

getHeatFlow
"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.

Implementation

{operation}{optionalParameter}
"compute sum over all relations."
    |sum|
    "init calculation"
    sum := 0.
    {loop}
    ^sum
{loop}
See Pattern FollowRelation
.
{dontLoop}
"1:1 relation."
    self {relation} instance notNil ifTrue:
    [ sum := sum + self {relation} instance
        {remoteOperation}{optionalParameter} ].
{doLoop}
"1:n relation."
    self {relation} connections do:
        [   :anObject|
            sum := sum + anObject
                {remoteOperation}{optionalParameter}
        ].
{optionalParameter}
If {parameter} is set, {optionalParameter} will be replaced with ': {parameter}', else it is replaced by an empty string.

Related Patterns

FollowRelation .

PEdit description

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

previous page next page up   Table of Contents PSiGene