Class Diagram Detailed Design For Class ATM
Class Diagram Detailed Design For Class ATM
Detailed Design
A major task of detailed design is to spell out, in detail, the attributes and methods needed by each class (the
second and third "compartments" of the representation for each class in a class diagram.)
The methods needed by each class are implicit in the responsibilities assigned to the class in the CRC cards,
and become explicit in the Interaction Diagrams. A responsibility listed for a class on its CRC card generally
maps into a method or methods in the detailed design. Likewise, any time an object belonging to a given
class is shown as the recipient of a message in either a Sequence or Collaboration Diagram, the class needs a
corresponding method. Many of the needed attributes are also either explicitly or implicitly present in the
diagrams; the need for others becomes evident as the code for the class is being written. (Thus detailed design
and coding are a "round trip" process - detailed design dictates coding, and coding leads to elaboration of the
detailed design.)
The class ATM is made an active class - that is, the ATM object has its own thread. Using the Java
thread facllity leads to defining a run() method in this class whose body is executed by the ATM's
thread. The fact that class ATM is active is indicated in class diagrams by enclosing it in a heavier
outline.
Certain signals initiate computation - e.g. the signals from the operator console when the state of the
switch is changed, or from the card reader when a card is inserted. In the GUI simulation of the ATM,
these signals are sent by the "actionPerformed()" method of the appropriate GUI button; in a real ATM
they would be sent by the physical components themselves, which might then also need to be active
classes. (Note: this forms an exception to the rule that a responsibility on a CRC card translates into a
method in the design - in this case the class sends a signal, rather than receiving it, so it does not need a
method directly corresponding to the responsibility.)
The Transaction hierarchy consists of the abstract class Transaction and four concrete subclasses
(Withdrawal, Deposit, Transfer and Inquiry). The class Transaction has a "virtual constructor" called
makeTransaction() which asks the customer to choose a transaction type and then constructs and
returns an object of the appropriate subclass. The Transaction class is made responsible for carrying out
the Transaction use case and the Invalid PIN extension; for the former, it makes use of abstract
methods getSpecificsFromCustomer() and completeTransaction() which are implemented concretely
by each subclass.
The class Receipt is abstract. The completeTransaction() method of each kind of transaction creates a
concrete instance that contains the information relevant to that kind of transaction.
The class Status is abstract. The send() method of NetworkToBank constructs a concrete instance that
contains the information appropriate to the response received from the bank to a particular message.
In the design below, each class is developed in isolation. No attempt is made to connect each class to related
classes as in the class diagram, because the resulting picture would not fit on a displayable web page.
Therefore, this detailed design should be viewed in conjunction with the Class Diagram developed earlier.
1 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
ATM
- id: int
- place: String
- bankName: String
- bankAddress: InetAddress
- cardReader: CardReader
- cashDispenser: CashDispenser
- customerConsole: CustomerConsole
- envelopeAcceptor: EnvelopeAcceptor
- log: Log
- networkToBank: NetworkToBank
- operatorPanel: OperatorPanel
2 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
- receiptPrinter: ReceiptPrinter
- state: int
- switchOn: boolean
- cardInserted: boolean
- OFF_STATE: final int
- IDLE_STATE: final int
- SERVING_CUSTOMER_STATE: final int
CardReader
- atm: ATM
+ CardReader(atm: ATM)
+ readCard(): Card
+ ejectCard()
+ retainCard()
3 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
CashDispenser
- log: Log
- cashOnHand: Money
+ CashDispenser(log: Log)
+ setInitialCash(initialCash: Money)
+ checkCashOnHand(amount: Money): boolean
+ dispenseCash(amount: Money)
CustomerConsole
+ CustomerConsole()
+ display(message: String)
+ readPIN(prompt: String): int throws Cancelled
+ readMenuChoice(prompt: String, menu: String []): int throws Cancelled
+ readAmount(prompt: String): Money throws Cancelled
EnvelopeAcceptor
- log: Log
+ EnvelopeAcceptor(log: Log)
+ acceptEnvelope() throws Cancelled
Log
4 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
+ Log()
+ logSend(message: Message)
+ logResponse(status: Status)
+ logCashDispensed(amount: Money)
+ logEnvelopeAccepted()
NetworkToBank
- log: Log
- bankAddress: InetAddress
OperatorPanel
- atm: ATM
+ OperatorPanel(atm: ATM)
+ getInitialCash(): Money
ReceiptPrinter
+ ReceiptPrinter()
+ printReceipt(receipt: Receipt)
5 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
Session
- atm: ATM
- pin: int
- state: int
- READING_CARD_STATE: final int
- READING_PIN_STATE: final int
- CHOOSING_TRANSACTION_STATE: final int
- PERFORMING_TRANSACTION_STATE: final int
- EJECTING_CARD_STATE: final int
- FINAL_STATE: final int
+ Session(atm: ATM)>
+ performSession()
+ setPIN(int pin)
Transaction
# atm: ATM
# session: Session
# card: Card
# pin: int
# serialNumber: int
# message: Message
# balances: Balances
- TRANSACTION_TYPES_MENU: final String []
- nextSerialNumber: int
- state: int
- GETTING_SPECIFICS_STATE: final int
- SENDING_TO_BANK_STATE: final int
- INVALID_PIN_STATE: final int
- COMPLETING_TRANSACTION_STATE: final int
- PRINTING_RECEIPT_STATE: final int
6 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
Withdrawal
- from: int
- amount: Money
Deposit
- to: int
- amount: Money
Transfer
7 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
- from: int
- to: int
- amount: Money
Inquiry
- from: int
AccountInformation
Balances
- total: Money
- available: Money
+ Balances()
+ setBalances(total: Money, available: Money)
+ getTotal(): Money
8 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
+ getAvailable(): Money
Card
- number: int
+ Card(number: int)
+ getNumber(): int
Message
+ Message(messageCode: int, cardNumber: Card, pin: int, serialNumber: int, fromAccount: int, toAccount:
int, amount: Money)
+ toString(): String
+ setPIN(pin: int)
+ getMessageCode(): int
+ getCard(): Card
+ getPIN(): int
+ getSerialNumber(): int
+ getFromAccount(): int
9 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
+ getToAccount(): int
+ getAmount(): Money
Money
- cents: long
+ Money(dollars: int)
+ Money(dollars: int, cents: int)
+ Money(toCopy: Money)
+ toString(): String
+ add(amountToAdd: Money)
+ subtract(amountToSubtract: Money)
+ lessEqual(compareTo: Money): boolean
Receipt
- headingPortion: String []
# detailsPortion(): String []
- balancesPortion: String []
Status
+ toString(): String
+ isSuccess(): boolean
+ isInvalidPIN(): boolean
10 of 11 7/25/2019, 5:19 AM
Detailed Design http://www.math-cs.gordon.edu/courses/cs211/ATMExample/DetailedDe...
+ getMessage(): String
Copyright © 2000, 2001, 2002 - Russell C. Bjork. Permission for non-commercial reproduction for educational use is hereby granted; all other rights are
reserved.
11 of 11 7/25/2019, 5:19 AM