Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial

  • Loading branch information...
commit 985418cce34bf4e2676b2fddec9eec7adfaaa663 1 parent 25b62ac
Wouter Scherphof authored
11 Controller.js
... ... @@ -0,0 +1,11 @@
  1 +var Model = require('./Model');
  2 +var TransferMoneyContext = require('./TransferMoneyContext');
  3 +
  4 +exports.transfer = function (amount, source, destination) {
  5 + var sourceAccount = Model.Account.findByNumber(source);
  6 + var destinationAccount = Model.Account.findByNumber(destination);
  7 + var context = new TransferMoneyContext(amount, sourceAccount, destinationAccount);
  8 + context.enact();
  9 +};
  10 +
  11 +
21 Model.js
... ... @@ -0,0 +1,21 @@
  1 +function Account () {
  2 + this.number = null; // hack
  3 + this.balance = 1000; // hack
  4 +}
  5 +Account.prototype.increaseBalance = function (amount) {
  6 + this.balance += amount;
  7 +};
  8 +Account.prototype.decreaseBalance = function (amount) {
  9 + this.balance -= amount;
  10 +};
  11 +Account.prototype.log = function (message) {
  12 + console.log({account: this, message: message});
  13 +};
  14 +
  15 +exports.Account = {
  16 + findByNumber: function (number) {
  17 + var account = new Account();
  18 + account.number = number; // hack
  19 + return account;
  20 + }
  21 +};
2  README.md
Source Rendered
... ... @@ -1,4 +1,4 @@
1 1 dciBank
2 2 =======
3 3
4   -The Bank example of DCI, in JavaScript
  4 +The Bank example of DCI, in JavaScript.
29 TransferMoneyContext.js
... ... @@ -0,0 +1,29 @@
  1 +function withTransferMoneySource () {
  2 + this.transferTo = function (amount, sink) {
  3 + this.decreaseBalance(amount);
  4 + sink.transferFrom(amount, this);
  5 + this.log({out: amount, sink: sink.number});
  6 + };
  7 +}
  8 +
  9 +function withTransferMoneySink () {
  10 + this.transferFrom = function (amount, source) {
  11 + this.increaseBalance(amount);
  12 + this.log({in: amount, source: source.number});
  13 + };
  14 +}
  15 +
  16 +function TransferMoneyContext (amount, sourceAccount, destinationAccount) {
  17 + this.amount = amount;
  18 + this.source = sourceAccount;
  19 + this.sink = destinationAccount;
  20 +
  21 + withTransferMoneySource.call(this.source);
  22 + withTransferMoneySink.call(this.sink);
  23 +}
  24 +
  25 +TransferMoneyContext.prototype.enact = function () {
  26 + this.source.transferTo(10, this.sink);
  27 +};
  28 +
  29 +module.exports = TransferMoneyContext;
3  View.js
... ... @@ -0,0 +1,3 @@
  1 +var controller = require('./Controller');
  2 +
  3 +controller.transfer(10, '5896495', '8743353');

0 comments on commit 985418c

Please sign in to comment.
Something went wrong with that request. Please try again.