§4.2 Callin modifiers (before, after, replace)

(a) Method composition

The kind of method composition is controlled by adding one of the modifiers before, after or replace after the "<-" token of the binding declaration.

(b) Additive composition

The before and after modifiers have the effect of adding a call to the role method at the beginning or end of the base method, resp.
In this case no data are transferred from the role to the base, so if the role method has a result, this will always be ignored.

Example code (Callin):
1
team class Company {
2
  protected class Employee playedBy Person {
3
    public void recalculateIncome() { ... }
4
    recalculateIncome <- after haveBirthday; // callin binding
5
  }
6
}

Line 4 declares a callin binding for the role method recalculateIncome() defined in line 3. In combination with the role binding in line 2 this has the following effect:

  • After every call of the method Person.haveBirthday the method Company.recalculateIncome is called.

(c) Replacing composition

The replace modifier causes only the role method to be invoked, replacing the base method.
In this case, if the base method declares a result, this should be provided by the role method. Special cases of return values in callin bindings are discussed in §4.3.(e)

(d) Callin methods

Role methods to be bound by a callin replacement binding must have the modifier callin. This modifier is only allowed for methods of a role class.
A method with the callin modifier can only be called

  • via a callin replace binding
  • by a super or tsuper call from an overriding callin method.

It is illegal for a callin method

  • to be called directly,
  • to be bound using a callout binding, and
  • to be bound to a base method using a before or after callin binding.

Despite these rules a second level role — which is played by the current role — can intercept the execution of a callin method using any form of callin binding.

A callin method cannot override a regular method and vice versa, however, overriding one callin method with another callin method is legal and dynamic binding applies to callin method just like regular methods.
A callin method must not declare its visibility using any of the modifiers public, protected or private. Since callin methods can only be invoked via callin bindings such visibility control would not be useful.