BB5 - A Bank Transfer Example

James Coplien has implemented a DCI infrastructure in C++. He has also developed a simple program that illustrates the DCI essentials. The Squeak/DCI code for roughly the same problem is documented here.

The example story is that a human uses an Automatic Teller Machine (ATM) to transfer funds from her checking account to her savings account. She knows that her checking account is account number 1111 and that her savings account is account number 2222. The amount she wants to transfer on this occasion is $500. The use case operation is the transfer of money from one account to another. We follow the DCI paradigm and organize our code in the two essential projections; Data and Context. The Interaction is the dynamic part of the Context.. In addition, we have a Testing projection where the BB5Testing class drives the program.

In the core of banking we find the General Ledger (GL); a collection of transactions where each transaction documents the transfer of a value from one account to another (or "transfer a quantity from one resource to another" in modern parlance). Transactions are immutable by law and international conventions. Like any database record, a transaction has no behavior. The system behavior (use case) in our example is the construction of a transaction from the input data. This behavior is not part of the GL (what the system IS), but of the bank transfer application (what the system DOES).

An important attribute of an account is its balance; the funds available to its owner. This is a derived attribute; it is computed by summing over selected GL transactions. We see our account objects as caches on the GL. Our program's task is to construct a new transaction while applying the appropriate checks, update the account caches, and add the new transaction to the GL.

There are two versions of the program. In BB5aBank, the GL is omitted to make version suitable for use in short presentations. A companion version, BB5bBank, includes updating the GL at the end of a successful transfer.

The code can be read and run in BabyIDE. Informally, the code can be read at

BB5aBank (no General Ledger):
reader-friendly version
printer-friendly version

There is a toggle for choosing between the versions at the top of the documents.

BB5bBank (with General Ledger)
reader-friendly version
printer-friendly version