Banking model
ATM
| transaction |
keeps balance | database |
deposit money | |
withdraw money | |
| transaction |
keeps balance | database |
deposit money | |
withdraw money | |
slide: The ATM example (2a)
The responsibilities of the transaction class
may be summarized as: the validation of user requests
and the execution of money transfers.
The responsibility for maintaining audit information is also
assigned to the transaction class.
To act as required, a transaction object
needs to communicate with a number of other objects.
It must acquire information from both the card-reader
and the database to check, for example,
whether the user has entered the right PIN code.
To validate a request, it must check whether the
account will be overdrawn or not.
To pay the requested money, it must instruct the
cash-dispenser to do so.
And it must contact the database to log the appropriate
audit information.
In contrast, an account only needs to respond
to the requests it receives from a transaction.
Apart from that, it must participate in committing the
transaction to the bank's database.
Note that the CRC method is non-specific about how
the collaborations are actually realized;
it is unclear which object will take the initiative.
To model these aspects we will need a more precise
notion of control
that tells us how the potential behavior
(or responsibility) of an object is activated.
The second group of classes may be called
interaction classes,
since these are meant to communicate with
entities in the outside world, outside from
the perspective of the system.
Also the bank's database may be considered
as belonging to the outside world,
since it stores the information concerning the
account and the authorization of customers
in a system-independent manner.
See slide [3-atm-2b].
Interaction classes
ATM
| event |
signals insertion | transaction |
decodes strip | |
| event |
signals insertion | transaction |
decodes strip | |
| event |
retrieves account | transaction |
records transaction | account |
authorization | database |
slide: The ATM example (2b)
Both the card-reader and the cash-dispenser
rely on a class called event,
which is needed to model the actions of the user.
For example, when a user inserts a bankcard,
we expect a transaction to start.
For this to happen, we must presuppose an underlying system
that dispatches the event to the card-reader,
which in turn notifies the teller machine
that a new transaction is to take place.
The flow of control between a transaction object
and the cash-dispenser is far more straightforward,
since a transaction object only needs to
issue the appropriate instruction.
However, the actual interaction between the
cash-dispenser and the underlying hardware,
that turns out the money, may be quite intricate.
The database may either respond directly to the request
coming from the account or transaction object
or it may respond to events
by taking the initiative to call the appropriate methods
of the account and transaction objects.
Whether the database may be accessed directly
or will only react to
events is actually dependent on the
control model we assume when developing the system model.
Instructor's Guide
intro,
methods,
objects,
contracts,
formal,
summary,
Q/A,
literature
Objects rarely live in isolation.
In a system of some complexity,
a number of different kinds of object
classes may usually be distinguished.
Each kind of class may be regarded as playing
a specific role in the system.
For example, when considering our ATM,
classes such as card-reader and cash-dispenser
are of a completely different kind, and play a completely
different role, than the classes
account and database for instance, or the classes
event and transaction.
Often it will take some
experimentation to decide how control must
be distributed among the objects comprising the system.
Although
the framework chosen for the development of the system
may partly determine the control model,
there will usually be ample choice left for the designer of
the system to define the interactions between objects.
Object roles
- actor -- operates (suffers no operations)
- server -- suffers operations
- agent -- suffers and operates ( actor & server)
slide: Object roles
An important function of the design document
is to elucidate the role of each object class
in the system, and to point out
how the objects cooperate to complete the task.
In [Booch86], a distinction is made between objects
that suffer no operations (actors),
objects that only suffer operations (servers)
and objects that both suffer and require operations
(agents).
Such a characterization in terms of initiative
may give a first indication of
the role an object plays in the system.
For example, the account class in our ATM example
is best characterized as a server class,
whereas the transaction class may be regarded,
in the terminology of [Booch86], as an actor
class, since it actively controls the computation.
In many cases, the software control model
adopted will also influence the way in which individual
objects are supposed to behave.
See slide [3-roles].
With respect to a global view of
the system, it is necessary to ensure that each object class
is completely defined,
that is to establish that each class provides a
sufficiently complete
method interface.
In [Booch86], a characterization is given of the
kinds of methods that may occur in an interface.
These include methods to create or destroy an
object, methods to modify the state of an object and methods
that only provide information on the state of
an object, or parts thereof.
Before being able to make final decisions
with respect to the functionality of a class, however,
it is generally necessary to get a clear
overall picture of the system first.
This requires what [Booch86] characterizes
as round trip gestalt design, which in other
words expresses the need to
analyze a little,
design a little,
implement a little,
test a little ...
(The notion of gestalt comes from
perception psychology, where it means a global
perceptual configuration emerging from the background.)