Skip to content

Implementation Role Feature 11

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

Title

Features of an object can be role-specific

Description

Attributes and behavior of an object may be overloaded on a by-role basis, i.e., different roles may declare the same features, but realize them 􏰀differently. If an object plays several of these roles simultaneously, it responds according to the role in which it is being addressed.

Implementation

(Different) roles (may) have (different) properties and behavior (see feature 1) and attaching them to players will create an (compound-) object aggregating all those role-specific features.

Additional hints

In case you are accessing behavior (methods/functions) or properties (class attributes) with the exact same signature (name, argument types and return type) but still want to distinguish the appropriate target (-role) context-wise, you have to define an implicit dispatch description (DispatchQuery).

E.g.:

implicit val dd =
  From(_.isInstanceOf[Account]).
  To(_.isInstanceOf[CheckingsAccount]).
  Through(anything).
  Bypassing(_.isInstanceOf[CheckingsAccount])

Please have a look at the ScalaDoc at DispatchQuery.scala for an explanation of the functions From, To, Through and Bypassing.

Clone this wiki locally