Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
OTJ Primer/Role Playing
< OTJ Primer
Revision as of 08:32, 8 July 2010 by Stephan.cs.tu-berlin.de (Talk | contribs) (New page: Role Playing is a new relation between classes/objects introduced by OT/J. ==Class-level Binding== At class level you simply write: <source lang="otj">public class Employee playe...)
Role Playing is a new relation between classes/objects introduced by OT/J.
Class-level Binding
At class level you simply write:
public class Employee playedBy Person { /* details omitted */ }
The above declaration has the effect that each runtime instance of Employee will be associated to a corresponding instance of Person. The compiler statically guarantees that there will never be an Employee instance without an associated Person instance. E.g., the default constructor for a bound role like Employee requires a non-null Person argument so you can write:
Person joe = new Person("Joe"); Employee joeProgrammer = new Employee(joe);
The syntax of OT/J does not allow direct access to the base link from a role instance to its base instance, but such access is controlled using callout method bindings, see next.
Method-level Bindings
...