string currency, description, address, unit, expireDate
agent Paradise, Retailer [address]
resource Capital [currency], Cream [description, expireDate, unit]
process BuyCream { CashDisbursement: 1 flow Capital(Paradice -> Retailer)
CreamDelivery: 1 flow Cream (Retailer -> Paradice)
Discount: 0..1 flow Capital(Retailer -> Paradice)
}
Figure 6: Specification corresponding to Figure 2.
The types of fields are declared in the first line.
Two agents, Paradice and Retailer, are declared in the
second line and two resources, Capital and Cream
with their fields, are declared in line 3. Then the
process, BuyCream, is declared. It consists of three
events. The declaration of the first event, CashDis-
bursement, can be read as: ”CashDisbursement must
occur exactly once in a BuyCream process and is a
flow of Capital from Paradice to a Retailer.” This ex-
ample also shows an optional Discount event, where
the multiplicity is 0..1. The full specification has
six other processes: OwnerShip, MachineOwner-
Ship, BuyElectricity, AquireLabour, MakeIcecream
and SellIcecream. These are omitted here for brevity
as they have a similar structure.
4.1 Language Implementation
The language is implemented using Objective Caml
(Smith, 2006; May, 2006), which is a programming
language supporting functional as well as object-
oriented programming. This makes it particularly
suitable for constructing a programming model on the
basis of a REA specification – the classes in the pro-
gram are related to the specification and the classes in
the Object-Z meta-model in a very direct manner.
The implementation is divided into two parts.
First, the specification is analyzed to check whether it
satisfied all properties of the meta-model. The func-
tional part of Objective Caml proved very useful for
this purpose as, for example, the properties in the
meta-model, e.g. [b], [c], [d] and [e] in Figure 5, are
programmed in a straightforward way. If the speci-
fication is consistent, then an XML representation is
generated. In the second part, which is addressed in
the next section, a web-application is generated on the
basis of that XML representation.
5 AUTOMATED GENERATION
OF APPLICATIONS
Having a consistent REA model, given now as an
XML document, we can generate an application au-
tomatically. We have chosen to implement the appli-
cation in the web-framework, Ruby on Rails (Thomas
et al., 2004; Thomas and Hansson, 2006), which let
us focus on developing the features of the application
instead of Model-View-Control plumbing.
The generation of the implementation has three
major steps:
• generation of a database schema,
• generation of classes for the specified entities, and
• generation of a runtime storage system.
The main idea is that each of the REA entities:
resources, events, agents, resource types, legal en-
tities and processes have a table with relations cor-
responding to those from the runtime model. We
use the technique of Single Table Inheritance, so that
when the database structure is generated all fields
for the REA entities will be added to the table (e.g.
field description, field serial number). This gives us
the flexibility of having just one database table for all
specified types of the individual entities, but still let-
ting them have individual properties. Especially when
loading and saving it is useful to be able to treat them
the same way. Note however that a different approach
is needed for real-life ERP systems in order for the
system to scale. Figure 7 gives an overview of the
database.
We also generate a Ruby class for each
of the Single Table Inheritance types (e.g.
CreamDeliveryEvent a subclass of Event),
which will refer to the entries in a database table
with the same entity name (CreamDeliveryEvent in
events table).
The generated entities constitute a running web-
application and Figure 8 shows the web-interface gen-
erated from the Paradice example of which a part of
the specification is shown in Figure 6.
A user can register an event, e.g. a purchase of
cream, by simply clicking on the relevant business
process, click on the event and enter the details as
shown on Figure 8. If the resources are available in
the current state of the database and the entered data
are correct (e.g. type check of input fields) then the
event is registered and the database will change state
as described in the runtime model given in Object-Z.
The implementations of these events are derived
GENERATION OF ERP SYSTEMS FROM REA SPECIFICATIONS
17