§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):

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.
  • The base guard in line 4 ensures that Account objects only get ForeignAccount roles, if they belong to a different bank than the surrounding ATM team.
    It accesses the bank of the base via the base identifier.
  • The method binding guard in line 10 restricts the callin to debitWithFee to calls where the base method argument amount is lower than 1000.
  • A call to Account.debit causes a replace callin to debitWithFee only if both predicates evaluate to true.