Design ATM

Difficulty: Medium Source: awesome-low-level-design

Requirements

  1. Balance inquiry, cash withdrawal, cash deposit
  2. Authenticate with card and PIN
  3. Interact with bank backend
  4. Cash dispenser for distributing cash
  5. Handle concurrent access
  6. User-friendly interface

Class Diagram

Class Diagram


Classes, Interfaces and Enumerations

Class/Interface Description
Card card number, PIN
Account account number, balance; debit/credit methods
Transaction Abstract base; subclassed by WithdrawalTransaction and DepositTransaction
BankingService Manages accounts; ConcurrentHashMap for thread-safe access
CashDispenser Synchronized cash dispensing
ATM Coordinates BankingService and CashDispenser

Design Patterns Used

Pattern Application
Template Method Abstract Transaction class defines the algorithm skeleton; subclasses implement specific steps
Facade ATM class provides a simplified interface to BankingService and CashDispenser subsystems

Code Implementations

Language Source Code
Java View on GitHub
Python View on GitHub
C++ View on GitHub
C# View on GitHub
Go View on GitHub