The use case we would like to implement is to transfer money from a money source to a money sink. MoneySource and MoneySink are specific roles, played by an appropriate bank account.
The example is built up on the following entities:

UseCase: TransferMoney
From a users point of view the use case is the most important artifact in the code. That's because the use case contains business relevant code.
The following UseCase shall transfer money from a MoneySource to a MoneySink. Furthermore the amount of money shall be passed to the use case as an argument.

Let's have a closer look at the roles needed. The MoneySource has an interaction balance() to ask for the current balance. Furthermore the role supports withdraw() to withdraw an amount.
Note that we specify that this role might be played by an InvestmentAccount or a SavingsAccount.


Data: InvestmentAccount and SavingsAccount
The InvestmentAccount shall have a Balance member to store the actual balance. Furthermore the method withdraw() supports withdrawal. Therefore it might play the MoneySource role.

The SavingsAccount supports withdrawal and deposit. Therefore it might play the MoneySink or MoneySource role.

The context now puts it all together. Every context has to specify exactly one UseCase. In the following example we choose the TransferMoney UseCase.
Since the UseCase TransferMoney declares the usage of the Roles MoneySource and MoneySink actifsource asks us to provide the data which can play the roles.



Thanks to the strong actifsource type system it becomes possible that the content assist allows only Data which can play the role needed.

No comments:
Post a Comment