@@ -9,14 +9,9 @@ import scaladci._
99 4. Define role methods (what will those actors do...)
1010 5. Define the trigger that starts off the chain of interactions between the roles
1111
12- Normally we lowercase parameter names. "Source" and "Destination" of the MoneyTransfer
13- DCI context are an exception since we want to associate them with our role definitions.
1412 A role definition has to match an object identifier in the context scope. Not necessarily
1513 a class parameter, any val/var will do as long as the identifier name matches a defined role.
1614
17- Compared to this school-book example, Data classes, DCI Contexts and the runtime
18- environment would of course normally be in separate tiers.
19-
2015 More info - http://github.com/dci/scaladci
2116 Official website - http://fulloo.info
2217 Discussions - https://groups.google.com/forum/#!forum/object-composition
@@ -30,22 +25,22 @@ object MoneyTransferApp extends App {
3025 def decreaseBalance (amount : Int ) { balance -= amount }
3126 }
3227
33- // DCI Context - encapsulates a specific "process"/"use case"/" network of interactions" etc
28+ // DCI Context - encapsulates a network of interactions between role-playing objects (often implementing a use case)
3429 @ context
35- class MoneyTransfer (Source : Account , Destination : Account , amount : Int ) {
30+ class MoneyTransfer (source : Account , destination : Account , amount : Int ) {
3631
37- Source .withdraw // Trigger method setting off the use case
32+ source .withdraw // Trigger method setting off the use case
3833
39- role Source { // Role definition
34+ role source { // Role definition
4035 def withdraw () { // Role method
41- Source .decreaseBalance(amount) // Instance method
42- Destination .deposit // Role interacts with other role
36+ source .decreaseBalance(amount) // Instance method
37+ destination .deposit // Role interacts with other role
4338 }
4439 }
4540
46- role Destination {
41+ role destination {
4742 def deposit () {
48- Destination .increaseBalance(amount)
43+ destination .increaseBalance(amount)
4944 }
5045 }
5146 }
@@ -63,4 +58,5 @@ object MoneyTransferApp extends App {
6358 // Confirm that amount has transferred
6459 assert(salary.balance == 3000 - 700 , s " Salary balance should have been 3000 - 700 = 2300. Is now ${salary.balance}" )
6560 assert(budget.balance == 1000 + 700 , s " Budget balance should have been 1000 + 700 = 1700. Is now ${budget.balance}" )
61+ println(" SUCCES!" )
6662}
0 commit comments