<< §6.2.(d) Exceptions | ↑ Table of Contents ↑ |
§6.2.(e) Role migration
The following interfaces can be used to enable role migration:
IBaseMigratable
- This interface declares a method
and instructs the compiler to generate an implementation of this method for any bound role declaring
<B> void migrateToBase(B otherBase)
IBaseMigratable
as its super-interface.
The effect of callingmigrateToBase
on a role instance is to re-bind this role to a new base instance. The base instance must be compatible to the role's base class (in order to avoid problems during lifting the compiler may require the base to be of the exact type of the role's base class). Passingnull
to this method causes anNullPointerException
to be thrown. ITeamMigratable
- This interface declares a method
and instructs the compiler to generate an implementation of this method for any role declaring
<R> R<@otherTeam> migrateToTeam(final ITeam otherTeam)
ITeamMigratable
as its super-interface.
The effect of callingmigrateToTeam
on a role instance is to re-bind this role to become a contained part of a new team instance. The team instance must be of the exact type of the role's enclosing team. Passingnull
to this method causes aNullPointerException
to be thrown.Caveat:
This method intentionally breaks the rules of family polymorphism: any referenceR<@previousTeam> r
which was established before migration will incorrectly imply that the role's enclosing team still ispreviousTeam
, which is no longer true after migration. While this does not effect any method lookup (which is still safe), further assumptions based on a role's dependent type are invalidated by team migration. The same holds for references from the migrating role to any sibling role instances.
If the rules of family polymorphism should be maintained one should just refrain from declaringITeamMigratable
as a role's super-interface.
For both methods the signature declared in the interface is over-generalized, yet the compiler performs the necessary checks
to
ensure that role, base and team instances are indeed compatible and additionally the return type of migrateToTeam
is checked as a self-type, i.e., it reflects the exact type of the call target.
<< §6.2.(d) Exceptions | ↑ Table of Contents ↑ |