Sams Teach Yourself C++ in 21 Days

(singke) #1
Object-Oriented Analysis and Design 351

11


That said, most of the time these classes are discussed without distinguishing them
because the differences are highly abstract. When you say that in your model the Cat
class will have a Meow()method, understand that this means that you will put a Meow()
method into your C++ class as well.


You capture the design model’s classes in UML diagrams, and you capture the imple-
mentation’s C++ classes in code that can be compiled. The distinction is meaningful, yet
subtle.


In any case, the biggest stumbling block for many novices is finding the initial set of
classes and understanding what makes a well-designed class. One simplistic technique
suggests writing out the use-case scenarios and then creating a class for every noun.
Consider the following use-case scenario:


Customerchooses to withdraw cashfrom checking. Sufficient cash is in the
account, sufficient cash and receiptsare in the AT M, and the networkis up and run-
ning. The ATM asks the customer to indicate an amountfor the withdrawal, and the
customer asks for $300, a legal amount to withdraw at this time. The machinedis-
penses $300 and prints a receipt, and the customer takes the moneyand the receipt.

You might pull out of this scenario the following classes:



  • Customer

  • Cash

  • Checking

  • Account

  • Receipts
    •ATM

  • Network

  • Amount

  • Withdrawal

  • Machine

  • Money


You might then aggregate the synonyms to create this list, and then create classes for
each of these nouns:



  • Customer

  • Cash (money, amount, withdrawal)

  • Checking

Free download pdf