3.11. (Optional) Software Engineering Case
Study: Identifying the Classes in the ATM Requirements Specification
Now we begin designing the ATM system that
we introduced in Chapter
2. In this section, we identify the classes that
are needed to build the ATM system by analyzing the nouns and noun phrases that
appear in the requirements specification. We introduce UML class diagrams to
model the relationships between these classes. This is an important first step
in defining the structure of our system.
Identifying the Classes in a
System
We begin our OOD process by
identifying the classes required to build the ATM system. We'll eventually
describe these classes using UML class diagrams and implement these classes in
C++. First, we review the requirements specification of Section
2.7 and find key nouns and noun phrases to help us
identify classes that comprise the ATM system. We may decide that some of these
nouns and noun phrases are attributes of other classes in the system. We may
also conclude that some of the nouns do not correspond to parts of the system
and thus should not be modeled at all. Additional classes may become apparent to
us as we proceed through the design process.
Figure
3.18 lists the nouns and noun phrases in the
requirements specification. We list them from left to right in the order in
which they appear in the requirements specification. We list only the singular
form of each noun or noun phrase.
Fig. 3.18. Nouns and noun phrases in the requirements
specification.
| Nouns and noun phrases in the requirements
specification |
| bank |
money / fund |
account number |
| ATM |
screen |
PIN |
| user |
keypad |
bank database |
| customer |
cash dispenser |
balance inquiry |
| transaction |
$20 bill / cash |
withdrawal |
| account |
deposit slot |
deposit |
| balance |
deposit envelope |
|
We create classes only for the nouns
and noun phrases that have significance in the ATM system. We do not need to
model "bank" as a class, because the bank is not a part of the ATM system—the
bank simply wants us to build the ATM. "Customer" and "user" also represent
entities outside of the system—they are important because they interact with our
ATM system, but we do not need to model them as classes in the ATM software.
Recall that we modeled an ATM user (i.e., a bank customer) as the actor in the
use case diagram of Fig.
2.14.
We do not model "$20 bill" or
"deposit envelope" as classes. These are physical objects in the real world, but
they are not part of what is being automated. We can adequately represent the
presence of bills in the system using an attribute of the class that models the
cash dispenser. (We assign attributes to classes in Section
4.11.) For example, the cash dispenser maintains a count of the number of bills it contains. The
requirements specification doesn't say anything about what the system should do
with deposit envelopes after it receives them. We can assume that acknowledging
the receipt of an envelope—an operation performed by the class that models the
deposit slot—is sufficient to represent the presence of an envelope in the
system. (We assign operations to classes in Section
6.22.)
In our simplified ATM system, representing
various amounts of "money," including the "balance" of an account, as attributes
of other classes seems most appropriate. Likewise, the nouns "account number"
and "PIN" represent significant pieces of information in the ATM system. They
are important attributes of a bank account. They do not, however, exhibit
behaviors. Thus, we can most appropriately model them as attributes of an
account class.
Though the requirements specification
frequently describes a "transaction" in a general sense, we do not model the
broad notion of a financial transaction at this time. Instead, we model the
three types of transactions (i.e., "balance inquiry," "withdrawal" and
"deposit") as individual classes. These classes possess specific attributes
needed for executing the transactions they represent. For example, a withdrawal
needs to know the amount of money the user wants to withdraw. A balance inquiry,
however, does not require any additional data. Furthermore, the three
transaction classes exhibit unique behaviors. A withdrawal includes dispensing
cash to the user, whereas a deposit involves receiving deposit envelopes from
the user. [Note: In Section
13.10, we "factor out" common features of all
transactions into a general "transaction" class using the object-oriented
concepts of abstract classes and inheritance.]
We determine the classes for our
system based on the remaining nouns and noun phrases from Fig. 3.18.
Each of these refers to one or more of the following:
-
ATM
-
screen
-
keypad
-
cash dispenser
-
deposit slot
-
account
-
bank database
-
balance inquiry
-
withdrawal
-
deposit
The elements of this list are likely to
be classes we'll need to implement our system.
We can now model the classes in our
system based on the list we have created. We capitalize class names in the
design process—a UML convention—as we'll do when we write the actual C++ code
that implements our design. If the name of a class contains more than one word,
we run the words together and capitalize the first letter of each word (e.g.,
MultipleWordName). Using this convention, we create classes
ATM, Screen, Keypad, CashDispenser,
DepositSlot, Account, BankDatabase,
BalanceInquiry, Withdrawal and Deposit. We construct our system using all of these classes as
building blocks. Before we begin building the system, however, we must gain a
better understanding of how the classes relate to one another.
Modeling Classes
The UML enables us to model, via class diagrams, the classes in the ATM system and
their interrelationships. Figure 3.19 represents class
ATM. In the UML, each class is modeled
as a rectangle with three compartments. The top compartment contains the name of
the class, centered horizontally and in boldface. The middle compartment
contains the class's attributes. (We discuss attributes in Section
4.11 and Section
5.10.) The bottom compartment contains the
class's operations (discussed in Section
6.22). In Fig.
3.19 the middle and bottom compartments
are empty, because we have not yet determined this class's attributes and
operations.

Class diagrams also show the
relationships among the classes of the system. Figure 3.20 shows how our classes
ATM and Withdrawal relate to one
another. For the moment, we choose to model only this subset of classes for
simplicity; we present a more complete class diagram later in this section.
Notice that the rectangles representing classes in this diagram are not
subdivided into compartments. The UML allows the suppression of class attributes
and operations in this manner, when appropriate, to create more readable
diagrams. Such a diagram is said to be an elided
diagram—one in which some information, such as the
contents of the second and third compartments, is not modeled. We'll place
information in these compartments in Section
4.11 and Section
6.22.

In Fig.
3.20, the solid line that connects the two classes represents an association—a relationship
between classes. The numbers near each end of the line are multiplicity values,
which indicate how many objects of each class participate in the association. In
this case, following the line from one end to the other reveals that, at any
given moment, one ATM object participates
in an association with either zero or one Withdrawal objects—zero if the current user is not currently
performing a transaction or has requested a different type of transaction, and
one if the user has requested a withdrawal. The UML can model many types of
multiplicity. Figure
3.21 lists and explains the multiplicity
types.
Fig. 3.21. Multiplicity types.
| Symbol |
Meaning |
| 0 |
None |
| 1 |
One |
| m |
An integer value |
| 0..1 |
Zero or one |
| m,
n |
m or
n |
| m..n |
At least m, but not more than n |
| * |
Any nonnegative integer (zero or
more) |
| 0..* |
Zero or more (identical to
*) |
| 1..* |
One or
more |
An association can be named. For example, the word
Executes above the line connecting classes ATM and
Withdrawal in Fig. 3.20
indicates the name of that association. This part of the diagram reads "one
object of class ATM executes zero or one objects of class
Withdrawal." Note that association names are
directional, as indicated by the filled arrowhead—so it would be improper, for
example, to read the preceding association from right to left as "zero or one
objects of class Withdrawal execute one object of
class ATM."
The word currentTransaction at the Withdrawal
end of the association line in Fig. 3.20 is a role name, which identifies the role the
Withdrawal object plays in its relationship with the ATM. A role name adds meaning to an association between
classes by identifying the role a class plays in the context of an association.
A class can play several roles in the same system. For example, in a school
personnel system, a person may play the role of "professor" when relating to
students. The same person may take on the role of "colleague" when participating
in a relationship with another professor, and "coach" when coaching student
athletes. In Fig.
3.20, the role name currentTransaction
indicates that the Withdrawal object participating in
the Executes association with an object of
class ATM represents the
transaction currently being processed by the ATM. In other contexts, a
Withdrawal object may take on other roles (e.g.,
the previous transaction). Notice that we do not specify a role name for the
ATM end of the Executes association.
Role names in class diagrams are often omitted when the meaning of an
association is clear without them.
In addition to indicating simple
relationships, associations can specify more complex relationships, such as
objects of one class being composed of objects of other classes. Consider a
real-world automated teller machine. What "pieces" does a manufacturer put
together to build a working ATM? Our requirements specification tells us that
the ATM is composed of a screen, a keypad, a cash dispenser and a deposit
slot.
In Fig.
3.22, the solid diamonds attached to the association lines of class ATM
indicate that class ATM has a composition relationship with classes
Screen, Keypad, CashDispenser and
DepositSlot. Composition implies a whole/part relationship. The class
that has the composition symbol (the solid diamond)
on its end of the association line is the whole (in this case, ATM), and the classes on the other end of the association lines
are the parts—in this case, classes Screen, Keypad,
CashDispenser and DepositSlot. The compositions in Fig. 3.22 indicate that an object of class ATM is formed from one object of class Screen, one object of class CashDispenser, one object of class Keypad and one object of class
DepositSlot. The ATM "has a" screen, a keypad, a cash dispenser and a
deposit slot. The has-a relationship
defines composition. (We'll see in the Software Engineering Case Study section
in Chapter
13 that the is-a relationship defines
inheritance.)

According to the UML specification, composition relationships
have the following properties:
-
Only one class in the relationship
can represent the whole (i.e., the diamond can be placed on only one end of the
association line). For example, either the screen is part of the ATM or the ATM
is part of the screen, but the screen and the ATM cannot both represent the
whole in the relationship.
-
The parts in the composition relationship
exist only as long as the whole, and the whole is responsible for the creation
and destruction of its parts. For example, the act of constructing an ATM
includes manufacturing its parts. Furthermore, if the ATM is destroyed, its
screen, keypad, cash dispenser and deposit slot are also
destroyed.
-
A part may belong to only one whole at a
time, although the part may be removed and attached to another whole, which then
assumes responsibility for the part.
The solid diamonds in our class
diagrams indicate composition relationships that fulfill these three properties.
If a has-a
relationship does not satisfy one or more of these criteria, the UML specifies
that hollow diamonds be attached to the ends of association lines to indicate
aggregation—a
weaker form of composition. For example, a personal computer and a computer
monitor participate in an aggregation relationship—the computer has a monitor,
but the two parts can exist independently, and the same monitor can be attached
to multiple computers at once, thus violating the second and third properties of
composition.
Figure 3.23
shows a class diagram for the ATM system. This diagram models most of the
classes that we identified earlier in this section, as well as the associations
between them that we can infer from the requirements specification. [Note: Classes BalanceInquiry and
Deposit participate in associations
similar to those of class Withdrawal, so we
have chosen to omit them from this diagram to keep it simple. In Chapter
13, we expand our class diagram to include all the
classes in the ATM system.]
Figure
3.23 presents a graphical model of the structure of the
ATM system. This class diagram includes classes BankDatabase and
Account and several associations that were not
present in either Fig.
3.20 or Fig.
3.22. The class diagram shows that class ATM has a one-to-one relationship with class
BankDatabase—one ATM object authenticates users against one
BankDatabase object. In Fig. 3.23,
we also model the fact that the bank's database contains information about many
accounts—one object of class BankDatabase
participates in a composition relationship with zero or more objects of class
Account. Recall from Fig. 3.21 that
the multiplicity value 0..* at the Account end of the association between class
BankDatabase and class Account indicates
that zero or more objects of class Account take part in the association. Class
BankDatabase has a one-to-many
relationship with class Account—the BankDatabase
contains many Accounts. Similarly, class Account has a many-to-one relationship with class
BankDatabase—there can be many Accounts contained in the
BankDatabase. [Note: Recall from Fig. 3.21 that the multiplicity value * is identical to 0..*. We
include 0..* in our class diagrams for clarity.]
Figure 3.23 also indicates that if the user is performing a
withdrawal, "one object of class Withdrawal
accesses/modifies an account balance through one object of class
BankDatabase." We could have created an association directly between
class Withdrawal and class Account. The requirements specification, however,
states that the "ATM must interact with the bank's account information database"
to perform transactions. A bank account contains sensitive information, and
systems engineers must always consider the security of personal data when
designing a system. Thus, only the BankDatabase can access and manipulate an account directly. All other
parts of the system must interact with the database to retrieve or update
account information (e.g., an account balance).
The class diagram in Fig. 3.23
also models associations between class Withdrawal and classes
Screen, CashDispenser and Keypad. A withdrawal transaction includes prompting
the user to choose a withdrawal amount and receiving numeric input. These
actions require the use of the screen and the keypad, respectively. Furthermore,
dispensing cash to the user requires access to the cash dispenser.
Classes BalanceInquiry and Deposit, though not shown in Fig. 3.23, take
part in several associations with the other classes of the ATM system. Like
class Withdrawal, each of these classes associates with classes
ATM and BankDatabase. An object of class
BalanceInquiry also associates with an object of class
Screen to display the balance of an account to the
user. Class Deposit associates with classes Screen,
Keypad and DepositSlot. Like withdrawals,
deposit transactions require use of the screen and the keypad to display prompts
and receive input, respectively. To receive deposit envelopes, an object of
class Deposit accesses the deposit slot.
We have now identified the classes in our
ATM system (although we may discover others as we proceed with the design and
implementation). In Section
4.11, we determine the attributes for each of
these classes, and in Section
5.10, we use these attributes to examine how the
system changes over time. In Section
6.22, we determine the operations of the classes
in our system.
Software Engineering Case Study
Self-Review Exercises
| 3.1 |
Suppose we have a class Car that represents a car. Think of some of the different
pieces that a manufacturer would put together to produce a whole car. Create a
class diagram (similar to Fig. 3.22) that models some of the
composition relationships of class Car. |
| 3.2 |
Suppose we have a class File that
represents an electronic document in a standalone, non-networked computer
represented by class Computer. What sort of association exists between
class Computer and class File?
-
Class Computer has a one-to-one relationship with
class File.
-
Class Computer has a many-to-one relationship with
class File.
-
Class Computer has a one-to-many relationship with
class File.
-
Class Computer has a many-to-many relationship with
class File. |
| 3.3 |
State whether the following statement is true or false, and if
false, explain why: A
UML diagram in which a class's second and third compartments are not modeled is
said to be an elided diagram. |
| 3.4 |
Modify the class diagram of Fig. 3.23 to include class
Deposit instead of class
Withdrawal. |
Answers to Software Engineering
Case Study Self-Review Exercises
| 3.1 |
[Note: Answers may vary.] Figure 3.24 presents a class diagram that shows some of the
composition relationships of a class Car.

|
|
|
| 3.2 |
c. [Note: In a computer network, this relationship could be
many-to-many.] |
| 3.3 |
True. |
| 3.4 |
Figure
3.25 presents a class diagram for the ATM
including class Deposit instead of class
Withdrawal (as in Fig. 3.23). Note that
Deposit does not access CashDispenser, but does access
DepositSlot.
|