Simple Bank Transfer Example
written in Java-UC
This is a proram written in a first version of Java-Use Case (Java-UC). It is based on the DCI programming paradigm and implemented in injectionless Java.
The program was developed in Win7 with jdk1.8.0_45.
The complete code is in this file: ZIP
Unzip in an empty directory,
open Command Prompt (Windows), chdir to the chosen directory
run
javac *.java
java Test
The Test program creates two Account objects and initialize them with funds. Then it makes a successful transfer followd by an attempt at an illegal one.
There are four files: Test, Bank, and Account are simple POJO classes with no surprises. The Context class implements the complete DCI context with its roles and role methods. The Context code is organized as follows:
- The Roles
Names the roles and sets up the rolemap - The system operation
public void transfer (Integer amt, Integer from , Integer to , Bank bank)
This code is in 2 parts: Map the roles and trigger the interaction - The Role classes with role methods
Role methods are written, compiled, and stored in inner classes that are named after the role, e.g., FOOclass for role FOO. (All role names are written in UPPERCASE letters)
All calls on roles have this syntax: call(String toRole, String methodname , Object[] args)
Not pretty, better syntax is TBD. - The execution engine
Uses introspection to invoke a role method if it exists, otherwise invokes the same named instance method.
This code is copyright
©2015 Trygve Reenskaug, Oslo, Norway.
All rights reserved.
Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that the copies are not made for profit or commercial advantage and that copies bear this notice and full citation on the first page.