<< §2.4.1 Role creation via a lifting constructor | ↑ Table of Contents ↑ | §2.4.3 Role creation in the presence of smart lifting >> |
§2.4.2 Role creation via a regular constructor
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(..)
- A constructor of the corresponding base class (§A.5.3(c)), unless the role is involved in base class circularity (§2.1.2.(b)), in which case a base constructor call is illegal.
this(..)
- Another constructor of the same class.
super(..)
- A constructor of the super-class (normal
extends
), unless the super-class is bound to a different base class, in which case callingsuper(..)
is not legal. tsuper(..)
- A constructor of the corresponding role of the super-team (§A.5.4(e)). Also see the constraint in §1.3.2.(c).
(a) Unbound roles
Each constructor of a role that is not bound to a base class must use
one of this(..)
, super(..)
or tsuper(..)
.
(b) Bound roles
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.
(c) Super-call for bound roles
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.
- If the super role is bound to the same base class as the current role is,
- not writing a super-call causes the lifting constructor of the super role to be invoked.
- explicitly calling a super constructor requires the super constructor to either
- create a role instance using a base constructor call (directly or indirectly), or
- be a lifting constructor receiving a base instance, which the current role must provide as the argument.
- If the super role is bound but the current role refines the
playedBy
relationship (cf. §2.1.(c)),- a lifting constructor must be called explicitly passing a base object as the argument.
- If the role has an explicit or implicit super role which is unbound the constructor may optionally
call a super constructor (using
super(..)
ortsuper(..)
) prior to callingbase(..)
. 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.
<< §2.4.1 Role creation via a lifting constructor | ↑ Table of Contents ↑ | §2.4.3 Role creation in the presence of smart lifting >> |