Skip to content

Implementation Role Feature 1

Max Leuthäuser edited this page Oct 16, 2015 · 4 revisions

Title

Roles have properties and behaviors

Description

This very simple and basic feature of roles suggests that roles are indeed types. Hence SCROLL (and many other implementations out there) implements them as simple classes.

Implementation

Any class can be used as a role in SCROLL. Simply attach variables and methods/functions to implement this feature.

See e.g. the role of a customer in the banking example:

@Role class Customer() {
  var accounts = List[Accountable]()

  def addAccount(acc: Accountable) {
    accounts = accounts :+ acc
  }

  def listBalances() {
    accounts.foreach { a => info("Account: " + a + " -> " + (+a).balance) }
  }
}

Additional hints

  • The @Role-Annotation is optional and provides no additional functionality. You may used it to tag your roles (for better readability for other developers).
  • Be careful when using case classes as roles. The compiler generates equals- and hashCode-methods based on their constructor parameters. SCROLL uses this methods for comparing role instances which may lead to ambiguities.
Clone this wiki locally