Design an ATM Machine
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-04-16
Problem Statement
Design the Low-Level Design of an ATM system that allows customers of a bank to perform basic operations such as withdrawing money, depositing money, checking balance, and transferring funds. The system should be modular, extensible, and mimic the working of a real-world ATM.
Functional Requirements
1.User Authentication
•Authenticate user with Card + PIN.
•Handle incorrect PIN attempts (e.g., block after 3 tries).
2.Banking Operations
•Cash Withdrawal – Check balance & dispense appropriate denomination.
•Cash Deposit – Accept deposit and update balance.
•Balance Inquiry – Display available balance.
•Fund Transfer – Transfer money to another account.
3.ATM Machine Responsibilities
•Dispense cash in available denominations (100s, 500s, 2000s).
•Check if machine has enough balance/notes before transaction.
•Handle cases where exact denomination cannot be dispensed.
•Generate receipts for transactions.
4.Error Handling
•Insufficient funds in ATM or account.
•Card expired/blocked.
•Transaction timeout.
Non-Functional Requirements
•Extensibility → support future features like QR-based withdrawal, UPI integration.
•Modularity → use separate classes for ATM, Card, BankAccount, Transaction, etc.
•Concurrency → multiple users may access different ATMs simultaneously.
•Security → sensitive data (PIN, balance) should not be exposed.
Design Hints
•Entities:
•ATM → maintains cashInventory and coordinates transactions.
•Card → linked to a BankAccount.
•BankAccount → stores balance & account info.
•Transaction (abstract) → Withdrawal, Deposit, BalanceInquiry, Transfer.
•User → interacts via card + PIN.
•Patterns:
•Use State Pattern for ATM states (Idle, CardInserted, Authenticated, TransactionInProgress).
•Use Factory Pattern for creating Transaction objects.