Occasionally, you can describe the behavior
of objects in state machine terms. For example, you could express
the behavior of the stamp dispenser example from
HAS_0
, HAS_5
,
HAS_10
, HAS_15
add5
, add10
, returnCoins
dispenseStamp
, ret5
,
ret10
, ret15
A stamp dispenser's current state indicates
how much money has been inserted. If no money has been inserted,
the stamp dispenser is in HAS_0
state. If a nickel
has been inserted, the stamp dispenser is in HAS_5
state,
and so on. No HAS_20
state appears in the list, because
as soon as 20 cents is inserted, a stamp is automatically issued
and any change is returned.
The three messages represent the actions a
stamp dispenser user can take: inserting a nickel (add5
),
inserting a dime (add10
), or pressing the coin return lever
(returnCoins
). The four actions the stamp dispenser
can take are return a nickel (ret5
), return a dime
(ret10
), return 15 cents (ret15
), or dispense
a 20 cent stamp (dispenseStamp
).
Figure 4-1. The stamp dispenser state-transition diagram
Last Updated: Friday, April 26, 2002
Copyright © 1996-2002 Artima Software, Inc. All Rights Reserved. |
URL: http://www.artima.com/apidesign/object15.html
Artima.com is created by Bill Venners |