AG VLSI Design and Architecture

SFB 501 - Project D1: Application System "Buildings"

PSiGene

Pattern Catalog

[PSiGene]

5.3 Pattern MethodBranch

Intent

This pattern serves a basic functionality for branches in a method call. Depending on a condition one of two named methods is called.

Motivation

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.

Applicability

This pattern is applicable in simple cases only. For more complex situations it seems useful to either derive from or aggregate it.

Structure

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.

Participants

Objects
Attributes
Methods
Interfaces
Expressions

Collaborations

The target object should understand the methods given with methodOnTrue and methodOnFalse .

Implementation

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.

{branch}{optionalParameter}
({condition})
    ifTrue: [ ^self {methodOnTrue}{optionalParameter}]
    ifFalse: [ ^self {methodOnFalse}{optionalParameter}].
optionalParameter
: {parameter}

Related Patterns

MethodBranchOnRelation

PEdit description

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

previous page next page up   Table of Contents PSiGene