AG VLSI Design and Architecture

SFB 501 - Project D1: Application System "Buildings"

PSiGene

Pattern Catalog

[PSiGene]

4.1 Pattern FollowRelation

Intent

This Pattern can be used to follow a relation and call a method on all connected objects. Depending on the relations cardinality different code is generated.

Also Known As

Former Patterns: SingleIndirection (obsolete) , ComplexIndirection (obsolete) , ExtendedComplexIndirection (obsolete) .

Motivation

FollowRelation can be used in every case, when relations schould be traversed and an operation schould be called on all connected objects. For example, to print all connected objects a remote operation print could be called on each connected object. The Pattern can be used to follow several relations with any cardinalities.

Applicability

To use this Pattern, only a target class and the rolenames of the relations that should be followed has to be known.

Structure

Participants

Objects
Methods
Interfaces
Relations
Expressions

Collaborations

Consequences

Example:

FollowRelation
    bind: 'target' to: 'Room'; 
    bind: 'operation' to: 'printAll'; 
    bind: 'remoteOperation' to: 'print';
    bind: 'relation' to: '#(#LeftWalls #controlOfRoom)'.

This example will generate a method printAll which will call a print method on all connected LeftWalls and Controls. The Pattern takes care of the cardinality of the relations. The generated method in Smalltalk might look like this:

printAll
"follow all relations."

"1:n relation."
self LeftWalls connections do:
    [   :anObject|
        anObject print
    ].
"1:1 relation."
self controlOfRoom instance notNil ifTrue: 
[ self controlOfRoom instance print ].

Implementation

{operation}{optionalParameter}
"follow all relations"
{loop}{optionalParameter}
{loop}
For each relation one loop macro will be evaluated. These loop macros are replaced by a macro called {doLoop} if the actual relation is of cardinality 1:n and by {dontLoop} for cardinalities 1:1.
{dontLoop}{optionalParameter}
"1:1 relation."
self {relation} instance notNil ifTrue: 
    [ self {relation} instance
    {remoteOperation}{optionalParameter} ].
{doLoop}{optionalParameter}
"1:n relation."
    self {relation} connections do:
        [   :anObject|
            anObject {remoteOperation}{optionalParameter}
        ].
{optionalParameter}
If {parameter} is set, {optionalParameter} will be replaced with ': {parameter}', else it is replaced by an empty string.

Related Patterns

FollowRelationAndSum , FollowRelationAndCollectObjects .

PEdit description

Pattern FollowRelation Category indirection
    ObjectType use target
    SingleMethod implement operation
    ComplexRelation use relation
    Expression implement optional remoteOperation
    Expression implement optional parameter
End

previous page next page up   Table of Contents PSiGene