<< §2.1.2.(a) No role of the same team | ↑ Table of Contents ↑ | §2.1.2.(c) Base class decapsulation >> |
§2.1.2.(b) Cycles
The base class mentioned after playedBy
should normally not be
an enclosing type (at any depth) of the role class being defined.
This rule discourages the creation of cycles where the base instance of
a given role R
contains roles of the same type R
.
More generally this concerns any sequence of classes C1, C2, .. Cn
were each Ci+1
is either a member or the base class of
Ci
and Cn = C1
.
Such structures may be difficult to understand and have certain restrictions regarding
callout (§3.1.(a)) and base constructor calls (§2.4.2).
It is furthermore recommended to equip all roles that are played by an enclosing class with a guard predicate (§5.4) like this:
base when (MyTeam.this == base)
This will avoid that the role adapts other instances of the enclosing class which are not the enclosing instance.
It is prohibited to bind a role class to its own inner class.
<< §2.1.2.(a) No role of the same team | ↑ Table of Contents ↑ | §2.1.2.(c) Base class decapsulation >> |