The primary purpose of an ATM is to automate banking tasks for users, allowing them to check balances, withdraw cash, and deposit funds.
Behind the scenes, the ATM coordinates with the bank, manages account transactions, and interacts with hardware like the card reader and cash dispenser.
Including a limit of three pin attempts before locking the card is a good security measure.
For transactions, the ATM should handle withdraw and deposit operations.
withdrawals check for sufficient funds and deposit update the balance.
NOTE: To try the ATM visualizer below, insert the card, enter the PIN (1234),
pick an account,choose withdrawal or deposit, and see cash dispensed or received.
Three wrong PIN attempts will retain the card, matching the security policy above.
Functional Requirements
First, authenticate users via debit card and PIN.
Users should have an ability to select their current or savings account for transactions.
Support withdraw and deposit transactions, ensuring withdrawals validate sufficient funds and deposits update the account balance.
Design Rationale
An account number could be "0012345678". If stored as an integer, the leading zeros have no meaning and are lost.
To store the pin as a simple plain text, anyone who can get access to the database can access your pin.
Using a hash function to store the pin is a good way to store the pin.
Who will validate the pin? The ATM itself or the bank?
Rather than maintaining a transaction ledger for accountability and deriving the balance from it, as is typically in real-world banking, we simplify the system by directly updating the account balance during each transaction.
The bank class stores account objects and links them to cards for fast retrieval, enabling efficient card and PIN validation for authentication, account access for transactions, and funds availability checks for withdrawals.
Why have transaction as a class?
What is the State Design Pattern, and how does using the State Design Pattern for representing different states of an ATM state make sense?
We employ the state pattern with an ATM state class to manage the ATM's sequential workflow, such as transitioning from card insertion to pin entry, ensuring each day is encapsulated and clearly defined.
Sequence Flow
Object-Model Design
Account Class
Account class manages critical information, including:
- the account balance
- account number
- associated card number while using an account type enum to distinguish between account types like current or savings.
Card Class
- the PIN