should really be BankAccountCommand
| 35 | |
| 36 | // should really be BankAccountCommand |
| 37 | struct BankAccountCommand : Command |
| 38 | { |
| 39 | BankAccount& account; |
| 40 | enum Action { deposit, withdraw } action; |
| 41 | int amount; |
| 42 | |
| 43 | BankAccountCommand(BankAccount& account, |
| 44 | const Action action, const int amount) |
| 45 | : account(account), action(action), amount(amount) {} |
| 46 | |
| 47 | void call() const override |
| 48 | { |
| 49 | switch (action) |
| 50 | { |
| 51 | case deposit: |
| 52 | account.deposit(amount); |
| 53 | break; |
| 54 | case withdraw: |
| 55 | account.withdraw(amount); |
| 56 | break; |
| 57 | default: break; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void undo() const override |
| 62 | { |
| 63 | switch (action) |
| 64 | { |
| 65 | case withdraw: |
| 66 | account.deposit(amount); |
| 67 | break; |
| 68 | case deposit: |
| 69 | account.withdraw(amount); |
| 70 | break; |
| 71 | default: break; |
| 72 | } |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | // vector doesn't have virtual dtor, but who cares? |
| 77 | struct CompositeBankAccountCommand |
nothing calls this directly
no outgoing calls
no test coverage detected