| << §1 Teams and Roles | ↑ Table of Contents ↑ | §3 Callout Binding >> |
playedBy
relation, which declares that each role instances is associated to a
base instances.
playedBy) is called
its base class. Role instances may inherit and override
features from their base instance, which is declared using callout
(§3)
and callin (§4) method bindings.
playedBy relation
is called a bound role. The term bound role may also be
used for the instances of such a class.
Roles are bound to a base class by the playedBy keyword.
| 1 | public team class MyTeamA { |
| 2 | public class MyRole playedBy MyBase { |
| 3 | ... |
| 4 | } |
| 5 | } |
The playedBy relation is inherited along
explicit and implicit (§1.3.1.(c))
role inheritance.
An explicit sub-role (sub-class using extends)
can refine the playedBy relation to a more
specific base class (this is the basis for
smart lifting (§2.3.3)).
If a role class inherits several playedBy relations from
its super-class and its super-interfaces, there must be a most specific
base-class among these relations, which is conform to all other base-classes.
This most specific base-class is the base-class of the current role.
An implicit sub-role (according to §1.3.1.(c))
may only add a playedBy relation but never change an existing one.
Note however, that implicit inheritance may implicitly specialize an existing playedBy
relation (this advanced situation is illustrated in §2.7.(d)).
The playedBy relation by itself has no effect
on the behavior of role and base objects.
It is, however, the precondition for translation polymorphism
(lowering: §2.2 and lifting: §2.3)
and for method bindings (callout: §3 and callin: §4).
A role and its base object form one conceptual entity. The garbage collector will see a role
and its base object as linked in a bidirectional manner. As a result, a role cannot be
garbage collected if its base is still reachable and vice versa.
Internally a team manages its roles and corresponding bases using weak references.
When using one of the getAllRoles(..)
methods (see §6.1.(a)),
the result may be non-deterministic because these internal structures
may hold weak references to objects that will be collected by the next run of the
garbage collector. We advise clients of getAllRoles(..) to call
System.gc() prior to calling getAllRoles(..) in order
to ensure deterministic results.
Role base bindings may involve classes and/or interfaces.
An interface defined as a member of a team is a role interface and may therefore
have a playedBy clause. Also the type mentioned after the
playedBy keyword may be an interface.
Generally, the base class mentioned after playedBy must be
visible in the enclosing scope (see below (§2.1.2.(c)) for an exception).
Normally, this scope is defined just by the imports of the enclosing team.
For role files (§1.2.5.(b))
also additional imports in the role file are considered.
§2.1.2.(d) below defines how imports can be constrained so that certain types
can be used as base types, only.
The base class of any role class must not be a role of the same team.
It is also not allowed to declare a role class of the same name
as a base class bound to this or another role of the enclosing team,
if that base class is given with its simple name and resolved using a regular import.
Put differently, a base class mentioned after playedBy
may not be shadowed by any role class of the enclosing team.
Base imports as defined below (§2.1.2.(d)) relax this rule by
allowing to import a class as a base class only. In that case no shadowing occurs since the scopes for
base classes and roles are disjoint.
The base class mentioned after playedBy may not be
an enclosing type (at any depth) of the role class being defined.
This rule prohibits the creation of cycles where the base instance of
a given role R contains roles of the same type R.
More generally any sequence of classes C1, C2, .. Cn
were each Ci+1 is either a member or the base class of
Ci and Cn = C1 is forbidden.
Conversely, it is also prohibited to bind a role class to its own inner class.
If a base class referenced after playedBy exists but is not visible under normal visibility rules of Java,
this restriction may be overridden. This concept is called decapsulation, i.e., the opposite of encapsulation
(see also §3.4). A compiler should signal any occurrence of base class decapsulation. If a compiler supports to
configure warnings this may be used to let the user choose to (a) ignore base class decapsulation, (b) treat it as a warning
or even
(c) treat it as an error.
Decapsulation is not allowed if the base class is a confined role (see §7.2).
Within the current role a decapsulated base class can be mentioned in the right-hand-side of any method binding
(callout (§3) or callin (§4)). Also arguments in these positions are allowed to mention the decapsulated base class:
If the main type in a file denotes a team, the modifier base can be applied to an import in order to specify that this type
should be imported for application as a base type only. Example:
| 1 | import base some.pack.MyBase; |
| 2 | public team class MyTeam { |
| 3 | // simple name resolves to imported class: |
| 4 | protected class MyRole playedBy MyBase { } |
| 5 | MyBase illegalDeclaration; // base import does not apply for this position |
| 6 | } |
Types imported by a base import can only be used in the same positions where also base class decapsulation (§2.1.2.(c))
is applicable.
It is recommended that a type mentioned after the keyword playedBy is always imported with the base modifier, otherwise the compiler
will give a warning.
Base imports create a scope that is disjoint from the normal scope. Thus, names that are imported as base will never clash
with normally visible names
(in contrast to §1.4). More specifically, it is not a problem to use a base class's name also for its role if a base import is used.
It is not possible to specify a parameterized type as a role's base class. If a class to be bound as base class is generic the raw type must be used instead.
playedBy declaration is used at run-time
to associate role instances to base instances.
Specifying a parameterized base class would imply that only such base instances
are decorated by a role whose type is conform to the specified parameterized class.
However, the type parameters are not available at run-time, thus the run-time environment
is not able to decide which base instances should have a role and which should not.
This is due to the design of generics in Java which are realized by erasure.
Each instance of a bound role class internally stores a reference to its base object. The reference is guaranteed to exist for each bound role instance, and cannot be changed during its lifetime.
Retrieving the base object from a role object is called lowering. No other means exists for accessing the base reference.
The lowering translation is not meant to be invoked
by client code, but implicit translations are inserted by
the compiler at all places where a role type is provided while the
corresponding base type (or a super type) was expected.
In other words: lowering translations are inserted by the compiler at
all places in a program which would otherwise not be type correct
and which using lowering are statically type correct.
This may concern:
| 1 | public team class MyTeamA { |
| 2 | public class MyRole playedBy MyBase { ... } |
| 3 | void useMyBase(MyBase myb) {...} |
| 4 | MyRole returnMyRole() {...} |
| 5 | public void doSomething() { |
| 6 | MyRole r = new MyRole(new MyBase()); |
| 7 | MyBase b = r; |
| 8 | useMyBase(r); |
| 9 | MyBase b2 = returnMyRole(); |
| 10 | } |
| 11 | } |
Lowering translations are not inserted for
== or !=)
instanceof checks
For cases where lowering shall be forced see §2.2.(d) below.
The static type of an implicit lowering translation is the base class
declared using playedBy in the respective role class.
If a base type is also the super type of its role,
which frequently happens, if a base reference is known only by
the type Object, lowering cannot be deduced automatically,
since a type could be interpreted both as a role type and a base type.
These cases may need explicit lowering.
For this purpose the role class must declare to implement the interface
ILowerable (from org.objectteams.Team).
This will cause the compiler to generate a method
public Object lower()
for the given role class. Client code may use this method to explicitly request the base object of a given role object.
| 1 | public team class MyTeamA { |
| 2 | public class MyRole implements ILowerable playedBy MyBase { ... } |
| 3 | public void doSomething() { |
| 4 | MyRole r = new MyRole(new MyBase()); |
| 5 | Object oMyRole = r; |
| 6 | Object oMyBase = r.lower(); |
| 7 | } |
| 8 | } |
Lowering also works for arrays of role objects.
In order to lower an array of role objects,
a new array is created and filled with base objects, one for each
role object in the original array. The array may have any number
of dimensions at any shape. The lowered array will have exactly the
same shape.
Note, that each lowering translation will create a new array.
Lifting is the reverse translation of lowering. However, lifting is a bit more demanding, since a given base object may have zero to many role objects bound to it. Therefor, the lifting translation requires more context information and may require to create role objects on demand.
Retrieving a role for a given base object is called lifting. Lifting is guaranteed to yield the same role object for subsequent calls regarding the same base object, the same team instance and the same role class (see §2.3.4 for cases of ambiguity that are signaled by compiler warnings and possibly runtime exceptions).
The lifting translation is not meant to be invoked by client code, but translations are inserted by the compiler at the following locations:
A lifting translation statically expects a specific role class.
This expected role class must have a playedBy clause
(either directly, or inherited (explicitly or implicitly)
from a super role), to which the given base type is conform.
Lifting also works for arrays of role objects. For lifting an array of base objects a new array is created and filled with role objects, one for each base object in the original array. In contrast to the role objects themselves, lifted arrays are never reused for subsequent lifting invocations.
The term translation polymorphism
describes the fact that at certain points values can be passed which are not
conform to the respective declared type considering only regular
inheritance (extends). With translation polymorphism
it suffices that a value can be translated using lifting or lowering.
Lifting tries to reuse existing role objects so that role state persists across lifting and lowering. If no suitable role instance is found during lifting, a new role is created.
A role object is considered suitable for reuse during lifting, if these three items are identical:
For the relation between the statically required role type and the actual type of the role object see "smart lifting" (§2.3.3).
Lifting uses a default constructor which takes exactly one argument of the type
of the declared base class (after playedBy).
By default the compiler generates such a constructor for each bound role.
On the other hand, default constructors that take no arguments
(as in JLS §8.8.7) are never generated for bound roles.
The super-constructor to be invoked by a default lifting constructor
depends on whether the role's super class is a bound role or not.
If a role class declares a custom constructor with the same signature
as the default lifting constructor, this constructor is used during lifting.
This custom constructor may pre-assume that the role has been setup
properly regarding its base-link and registered in the team's internal map of roles.
If a bound role has an unbound super-class without an argumentless
constructor, providing a custom lifting constructor is obligatory,
because no legal default lifting constructor can be generated.
A non-static team-level method or constructor may declare a parameter with two types in order to explicitly denote a place of lifting. Using the syntax
public void m (BaseClass as RoleClass param) { stmts }a liftable parameter can be declared, provided the second type
(RoleClass) is a role of (playedBy) the first type (BaseClass).
Furthermore, the role type must be a role of the enclosing team class defining the given method.
The role type must be given by its simple (i.e., unqualified) name.
Such a signature requires the caller to provide a base object (here BaseClass), but
the callee receives a role object (here RoleClass).
In fact, the client sees a signature in which the "as RoleClass" part is omitted.
Compatibility between caller and callee sides is achieved by an implicitly inserted lifting translation.
A signature using declared lifting is only valid, if the requested lifting is possible
(see §2.3.3 and §2.3.4 for details).
Calling super or tsuper in a method or constructor which
declares lifting for one or more parameters refers to a method or constructor with role type parameters,
i.e., lifting takes place before super invocation. Nevertheless, the super method may also
have a declared lifting signature. It will then see the same role instance(s) as the current method.
If a parameter involving explicit lifting should be of an array type, the syntax is
public void m (BaseClass as RoleClass param[]) ...
Here the brackets denoting the array apply to both types, BaseClass
and RoleClass.
Also the argument of a catch block may apply declared lifting like in:
catch (BaseException as RoleClass param) { stmts }This syntax is only valid in a non-static scope of a team (directly or nested).
In the given example, RoleClass must be played by BaseException.
Note, that RoleClass itself need not be a throwable.
As the effect of this declaration the catch block will catch any exception of type BaseException
and provides it wrapped with a RoleClass instance to the subsequent block.
Also note, that re-throwing the given instance param has the semantics of implicitly lowering
the role to its base exception before throwing, because the role conforms to the required type
Throwable only via lowering.
| 1 | team class Super { |
| 2 | public class MyRole playedBy MyBase { ... } |
| 3 | void m (MyRole o) { ... }; |
| 4 | } |
| 5 | team class Sub extends Super { |
| 6 | void m (MyBase as MyRole o) { |
| 7 | // inside this method o is of type MyRole |
| 8 | super.m(o); |
| 9 | } |
| 10 | } |
| 11 | Sub s_team = new Sub(); |
| 12 | MyBase b = new MyBase(); |
| 13 | s_team.m(b); // clients see a parameter "MyBase o" |
m with a base instance (type MyBase) as its argument (line 13).
m, the argument is lifted such that the method body receives
the argument as of type MyRole (line 8).
In situations where role and base classes are part of some inheritance
hierarchies (extends), choosing the appropriate role class during
lifting involves the following rules:
If a base class B shall be lifted to a role class
R that is not bound to (playedBy)
B, but if a subclass of R
— say R2 —
is bound to B, lifting is statically setup to use
R2, the most general subclass of R that
is bound to B or one of its super-types.
replace
callin bindings (§4.5.(d)).
At runtime also the dynamic type of a base object is considered:
Lifting always tries to use a role class that is bound to the
exact class of the base object. Lifting considers all role–base
pairs bound by playedBy such that the role class is a
sub-class of the required (statically declared) role type
and the base class is a super-class of the
dynamic type of the base object.
From those possible pairs the most specific base class is chosen.
If multiple role classes are bound to this base class the most
specific of these classes is chosen.
In the above analysis gathering all role-base pairs is performed at
compile-time. From this follows, that a team class can only be
compiled when all its contained role classes are known and a role class
can never be compiled without its team.
The analysis includes all roles and their bindings that are inherited
from the super-team.
Smart lifting is not affected by abstractness of role classes. For the effect of abstract role classes see §2.5.

| role class | base class |
|---|---|
| class R1 | |
| class R2 extends R1 playedBy B2 | class B2 |
| class R3 extends R2 /* inherited: playedBy B2 */ | class B3 extends B2 |
| class R4 extends R3 playedBy B4 | class B4 extends B3 |
| class R5 extends R4 /* inherited: playedBy B4 */ | |
| class B6 extends B4 | |
| class R7 extends R5 playedBy B7 | class B7 extends B6 |
B3 to R1
this is statically refined to use R2 instead, because this
is the most general class declaring a binding to a super–class
of B3.
B6,
three steps select the appropriate role:
playedBy clauses (including those
that are inherited) the following role–base pairs are
candidates:(R2,B2), (R3,B2), (R4,B4) and (R5,B4).
B4 are chosen.
R4 and R5 role candidates,
from which the most specific R5 is finally chosen.
If the inheritance hierarchies of the involved base and role classes are given (like in the figure above)
the smart lifting algorithm can be rephrased to the following "graphical" rule:
B6 in the example) move upwards the the inheritance
relation until you reach a base class bound to a role class indicated by a «playedBy»
arrow pointing to the base class (B4). This role class must be conform to the requested role type.
Switch to the role side along this arrow (R4). Now move downwards the role inheritance hierarchy
as long as the subrole does not refine the playedBy relationship (indicated by another «playedBy» arrow).
The bottom role you reach this way (R5) is the role type selected by smart lifting.
While all examples so far have only shown 1-to-1 class bindings, several cases of multiple bindings are allowable. Ambiguities may be detected at compile time and/or at runtime.
A potential ambiguity is given,
if two role classes R1 and R2
exist such that
R1 and R2 are played by the
same base class B, and
R1 and R2 have a common
super role R0,
which is also bound to a base class B0, and
R1 nor
R2 is a (indirect) sub-class of the other.
B may not be liftable, because both role classes R1
and R2 are candidates and there is no reason to prefer one over the other.
In the above situation, trying to lift an instance of type B to the role type
R0 is an illegal lifting request. If R0 is bound
to the same base class B as its sub-roles R1 and R2 are,
role R0 is unliftable, meaning that no instance of R0
can ever by obtained by lifting.
| 1 | team class MyTeam { |
| 2 | public class SuperRole playedBy MyBase {...} |
| 3 | public class SubRoleA extends SuperRole {...} |
| 4 | public class SubRoleB extends SuperRole {...} |
| 5 | } |
A definite ambiguity is given if
B to any role
class R0 that is a common super role for R1 and R2.
| 1 | team class MyTeam { |
| 2 | public class SuperRole playedBy MyBase {...} |
| 3 | public class SubRoleA extends SuperRole playedBy SubBase {...} |
| 4 | public class SubRoleB extends SuperRole playedBy SubBase {...} |
| 5 | |
| 6 | public void useSuperRole(SubBase as SuperRole r) {...} |
| 7 | } |
At runtime actual ambiguity may occur if for the dynamic type of a base to be lifted the conditions of (b) above hold accordingly. Actual ambiguity is only possible in cases reported by the compiler as potential ambiguity.
org.objectteams.LiftingFailedException.
| 1 | team class MyTeam { |
| 2 | public class SuperRole playedBy MyBase {...} |
| 3 | public class SubRoleA extends SuperRole playedBy SubBase {...} |
| 4 | public class SubRoleB extends SuperRole playedBy SubBase {...} |
| 5 | |
| 6 | public void useSuperRole(MyBase as SuperRole r) {...} |
| 7 | } |
| 8 | // plus these calls: |
| 9 | MyTeam mt = new MyTeam(); |
| 10 | mt.useSuperRole(new SubBase()); |
In cases of potential ambiguity another runtime error may occur: a mismatching role is encountered when a role is found in the cache, which is not conform to the required type. This happens, if the base object has previously been lifted to a type that is incompatible with the currently requested type.
org.objectteams.WrongRoleException.
| 1 | team class MyTeam { |
| 2 | public class SuperRole playedBy MyBase {...} |
| 3 | public class SubRoleA extends SuperRole {...} |
| 4 | public class SubRoleB extends SuperRole {...} |
| 5 | |
| 6 | public void useRoleA(MyBase as SubRoleA r) {...} |
| 7 | public void useRoleB(MyBase as SubRoleB r) {...} |
| 8 | } |
| 9 | // plus these calls: |
| 10 | MyTeam mt = new MyTeam(); |
| 11 | MyBase b = new MyBase(); |
| 12 | mt.useRoleA(b); // creates a SubRoleA for b |
| 13 | mt.useRoleB(b); // finds the SubRoleA which is not compatible |
| 14 | // to the expected type SubRoleB. |
From the second item of §2.3.4.(a) follows, that for binding ambiguities different
role hierarchies are analyzed in isolation.
For this analysis only those role classes are considered that are bound to a
base class (directly using playedBy or by inheriting this relation
from another role class).
I.e., two role classes that have no common bound super role will never cause
any ambiguity.
Lifting is the normal technique by which role objects are created implicitly. This section defines under which conditions a role can also be created explicitly.
Lifting uses the default constructor for roles (see §2.3.1). This constructor can be invoked from client code, if the following rules are respected.
The lifting constructor can be used only within the enclosing team of
the role to be instantiated. Thus, qualified allocation expressions
(someTeam.new SomeRole(..)) may never use the lifting constructor.
If the argument to a lifting constructor invocation is a new
expression, creating a fresh base object, the use of the lifting constructor
is safe. Otherwise the rules of (c) below apply.
If it cannot be syntactically derived, that the argument to a lifting
constructor is a freshly created base object (b), a compile time warning will
signal that an additional runtime check is needed: It must be prevented that
a new role is created for a base object, which already has a role of the
required type in the given team. It is not possible to replace an existing
role by use of the lifting constructor. At runtime, any attempt to do so
will cause a org.objectteams.DuplicateRoleException to be thrown.
This exception can only occur in situations where the mentioned compile
time warning had been issued.
§6.1 will introduce reflective functions
which can be used to manually prevent errors like a duplicate role.
Roles may also be created explicitly using a custom constructor with arbitrary signature
other than the signature of the lifting constructor.
Within role constructors, four kinds of self-calls are possible:
base(..)this(..)super(..)extends), unless the super-class is bound to a different base class, in which case calling super(..) is not legal.
tsuper(..)Each constructor of a role that is not bound to a base class must use
one of this(..), super(..) or tsuper(..).
Each constructor of a bound role must directly or indirectly invoke either
a base(..) constructor or a lifting constructor (see §2.3.1).
Indirect calls to the base constructor or lifting constructor may use any of this(..), super(..)
or tsuper(..), which simply delegates the obligation to the called constructor.
If a constructor referenced by base(..) is not visible according to the
regular rules of Java, it may still be called using decapsulation (see
also §3.4, §2.1.2.(c)).
Note, that if the super or tsuper role is not bound, delegating the obligation to that unbound role will not work.
Instead of or prior to calling base(..) a constructor of a bound role explicitly or implicitly calls a super constructor.
Which constructor is applicable depends on the super role and its playedBy clause.
playedBy
relationship (cf. §2.1.(c)),
super(..) or tsuper(..)) prior to calling
base(..). Otherwise the default constructor is implicitly invoked.
When invoking a lifting constructor of a super role the base object can optionally be obtained by using a base constructor call as an expression:
super(base(<args>));
The language system evaluates the base constructor by creating an instance of the appropriate base class using a constructor with matching signature. Also the internal links are setup that are needed for accessing the base object from the role and for lifting the base object to the new role in the future.
The syntax for base constructors follows the rule that role implementations never directly refer to any names of base classes or their features.
Explicitly instantiating a role R1 bound to a base B where smart lifting of B to R1 would actually
provide a subrole R2 is dangerous: Instantiation enters the R1 into the team's internal cache. If at any time later lifting
this B to R2 is requested, which is a legal request, the runtime system will answer by throwing a org.objectteams.WrongRoleException
because it finds the R1 instead of the required R2.
For this reason, in this specific situation the explicit instantiation new R1(..) will be flagged by a warning.
The problem can be avoided by using R2 in the instantiation expression.
| 1 | public class B { void bm() {} } |
| 2 | public team class T { |
| 3 | protected class R1 playedBy B {...} |
| 4 | protected class R2 extends R1 { // inherits the binding to B |
| 5 | void rm() { /* body omitted */ } |
| 6 | } |
| 7 | public B getDecoratedB() { |
| 8 | return new R1(new B()); // compile-time warning! |
| 9 | } |
| 10 | public void requestLifting(B as R2 r) {} |
| 11 | } |
| 12 | // plus these calls: |
| 13 | T t = new T(); |
| 14 | B b = t.getDecoratedB(); // creates an R1 for b |
| 15 | t.requestLifting(b); // => |
B to the lifting constructor of R1
(see §2.4.1.(b)). In order to return this B instance lowering is implicitly used for the return statement.
b to R2 is requested but due to line 8 an R1 is found in the internal cache.
Overriding of role classes and dynamic binding of role types (§1.3.1.(e)) adds new cases to creation with respect to abstract classes.
Abstract role classes can indeed be used for object creation.
The effect of such a statement is that the team must be
marked abstract. Only those sub-teams are concrete
that provide concrete versions for all role classes used in
creation expressions.
This includes the case, where a
super-team has a concrete role class and creates
instances of this role class and only the sub-team changes
the status of this role class to abstract. Also here
the sub-team must be marked abstract, because it contains
an abstract role class that is used in creation expressions.
A team must be marked abstract if one of its relevant roles is abstract.
A role is relevant in this sense if
new expression
would require to create instances of the role class, or ifplayedBy clause.
playedBy clause.
If neither property, relevance nor irrelevance, can be shown for an abstract role, a warning is given in case the enclosing team is not abstract.
The role-base link is not meant to be accessed explicitly from programs,
but it is fully under the control of compiler and runtime environment.
Accessing features of a role's base object is done by
callout bindings (§3).
Yet, a keyword base exists, which can be used in the following
contexts:
If the base class of a role T1.R1 is again a team
T2, roles of that team T2 can be
externalized (see §1.2.2)
using base as their type anchor. Given that
R2 is a role of T2, one could write:
| 1 | public team class T1 { |
| 2 | protected class R1 playedBy T2 { |
| 3 | protected R2<@base> aRoleOfMyBase; |
| 4 | } |
| 5 | } |
This syntax is only legal within the body of the role T1.R1 which is bound
to the team T2 containing role R2.
A static type prefix can be used to disambiguate a base anchor, so the explicit variant
of the above type would be R2<@R1.base>.
It is not legal to use a type anchor containing base as an element in a path
of references like <@base.field>
or <@field.base>.
Within a role constructor (which is not the lifting constructor)
the syntax base(arguments) causes an instance
of the bound base class to be created and linked (see §2.4.2).
Within a callin method (§4.2.(d))
an expression base.m(args) is used to invoke the
originally called method (see §4.3).
Guard predicates (§5.4) can
be specified to act on the base side using the base when keywords.
Within such a base guard predicate base is interpreted as a special identifier
holding a reference to the base object that is about to be lifted
for the sake of a callin method interception (see §5.4.2.(a)).
An expression at the right-hand side of a parameter mapping
(parameter in a callin binding (§4.4) or
result in a callout binding (§3.2.(c)) ) may use the keyword base
to refer to the bound base instance. Such usage requires the role method bound in this method binding to be non-static.
In all cases, the base reference is immutable,
i.e., base can never appear as the left-hand-side of an assignment.
This section discusses how role containment and the playedBy relationship can be combined. It does not define new rules, but illustrates rules defined above. The central idea is that any class can have more than one of the three flavors team, role, and base.
If a role (contained in a team) is also a team (marked with the team modifier)
it is a nested team. The depth of nesting is not restricted.
If the base class to which a role is bound using playedBy is a team,
the role is said to be stacked on the base team.
If roles of a team Secondary are played by roles of another team Primary
(i.e., base classes are roles), the team Secondary defines a layer over the team Primary.
Such layering requires a final reference anchor from Secondary to an instance of Primary.
All playedBy declarations within Secondary specify their base classes anchored to that final link anchor.

Due to the anchored base types, layered teams implicitly support the following guarantee:
all base objects of roles of Secondary are contained within the team instance specified by the link anchor.
If roles of Secondary contain any callin bindings to non-static base methods, these will be triggered only
when a base method is invoked on a base instance contained in the team specified by anchor.
In accordance with §2.6.(a) the anchor in such anchored playedBy declarations
could also be the pseudo identifier base, provided that Secondary is a nested team,
which has a playedBy binding to Primary as its base class.
This situation is part of the second example below (§2.7.(d)) (see T1 playedBy TB1).
According to §2.1.(d) an implicit sub-role may implicitly specialize an existing playedBy relation.
This requires the base class to be specified relative to some implicit (OuterTeam.this) or explicit (OuterTeam.base) team anchor.
Specializing that team anchor automatically specializes the playedBy declaration, too.
This rule never requires any action from a programmer but only explains the interpretation of a playedBy declaration in
complex situations.
|
![]() |
|
![]() |
| << §1 Teams and Roles | ↑ Table of Contents ↑ | §3 Callout Binding >> |
Effects:
An instance of type
MyRoleis lowered to typeMyBasewhenb(line 7)MyBase(line 8)MyBase(line 9)Note: The constructor call in line 6 uses the lifting constructor as defined in §2.4.1