/
MoneyTransfer.cs
57 lines (50 loc) · 1.51 KB
/
MoneyTransfer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Marvin.Examples
{
[Context]
public class MoneyTransfer<TSource, TDestination>
where TSource : ICollection<LedgerEntry>
where TDestination : ICollection<LedgerEntry>
{
public MoneyTransfer(Account<TSource> source, Account<TDestination> destination, decimal amount)
{
Source = source;
Destination = destination;
Amount = amount;
}
[Role]
private class Source : Account<TSource>
{
void Withdraw(decimal amount)
{
this.DecreaseBalance(amount);
}
void Transfer(decimal amount)
{
Console.WriteLine("Source balance is: " + this.Balance);
Console.WriteLine("Destination balance is: " + Destination.Balance);
Destination.Deposit(amount);
this.Withdraw(amount);
Console.WriteLine("Source balance is now: " + this.Balance);
Console.WriteLine("Destination balance is now: " + Destination.Balance);
}
}
[Role]
private class Destination : Account<TDestination>
{
void Deposit(decimal amount)
{
this.IncreaseBalance(amount);
}
}
[Role]
public class Amount { }
public void Trans()
{
Source.Transfer(Amount);
}
}
}