-
-
Notifications
You must be signed in to change notification settings - Fork 12
Implementation Role Feature 1
Max Leuthäuser edited this page Oct 16, 2015
·
4 revisions
Roles have properties and behaviors
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.
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) }
}
}
- 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
- andhashCode
-methods based on their constructor parameters. SCROLL uses this methods for comparing role instances which may lead to ambiguities.