-
-
Notifications
You must be signed in to change notification settings - Fork 12
Implementation Role Feature 18
Max Leuthäuser edited this page Nov 6, 2015
·
3 revisions
Roles can be grouped and constrained together
Role groups allow to constrain how often a set of role types can be played.
Consider for example the following code:
// creating two player objects
val acc1 = new Account()
val acc2 = new Account()
// and a new compartment instance
new Transaction {
// with two roles
class Source
class Target
val source = new Source
val target = new Target
// this role group enforces XOR between the two given role types, i.e.
// that a player is allowed to play exactly one of them (first tuple of integers)
// and that both roles have to played, i.e. in sum two (second tuple).
RoleGroup("Transaction").containing[Source, Target](1, 1)(2, 2)
// this will work
RoleGroupsChecked {
acc1 play source
acc2 play target
}
// this will throw a RuntimeException because the Target role is not played at all anymore
RoleGroupsChecked {
acc2 drop target
}
// this will throw a RuntimeException as well because the XOR restriction is violated
RoleGroupsChecked {
acc1 play target
}
}None.