§5.4.3 Multiple guards
Due to the different ranges of applicability different guards may affect the same method binding.
In that case all applicable guards are conjoined using a logical and.
Any guard is interpreted as the conjunction of these predicates (if present):
- The direct predicate expression of the guard.
- The next outer guard along the chain
method binding -> method -> role level -> team level
- The guard at the same level that is inherited from the implicit super role.
- The guard at the same level that is inherited from the explicit super role.
Example code (Guard Predicates):
| 1 |
public team class ATM { |
| 2 |
private Bank myBank; |
| 3 |
public class ForeignAccount playedBy Account |
| 4 |
base when (!ATM.this.myBank.equals(base.getBank())) |
| 5 |
{ |
| 6 |
callin void debitWithFee(int amount) { |
| 7 |
base.debitWithFee(fee+amount); |
| 8 |
} |
| 9 |
void debitWithFee(int i) <- replace void debit(int amount) |
| 10 |
base when (amount < 1000); |
| 11 |
} |
| 12 |
} |
Effects:
The team in this example causes that an additional fee has to be payed while debiting less than 1000 Euros from a "foreign" account.Accountobjects only getForeignAccountroles, if they belong to a different bank than the surroundingATMteam.It accesses the bank of the base via the
baseidentifier.debitWithFeeto calls where the base method argumentamountis lower than 1000.Account.debitcauses a replace callin todebitWithFeeonly if both predicates evaluate to true.