The ATM system needs to cater to the following key functionalities:
The primary objects in this system are:
ATM ↔ User: The ATM interacts with the user for authentication and transaction input.
Card ↔ User: The user provides their card to the ATM for identification.
Card ↔ Account: The card is linked to one or more accounts.
Transaction ↔ Account: Transactions modify the balance of the associated account.
ATM ↔ Bank: The ATM communicates with the bank to validate transactions and update account details.
Account Types:
Transaction Types:
ATM Components:
Singleton Pattern: Ensure only one instance of the ATM interface or bank service exists.
Factory Pattern: Use for creating transaction objects based on user input.
Observer Pattern: Notify the bank of any changes in account state or transactions.
Strategy Pattern: Use for different account types (savings, checking) and transaction handling.
class ATM:
def __init__(self, bank):
self.bank = bank
self.cash_dispenser = CashDispenser()
self.card_reader = CardReader()
self.screen = Screen()
self.keypad = Keypad()
def authenticate_user(self, card, pin):
return self.bank.validate_pin(card, pin)
def execute_transaction(self, transaction):
return transaction.perform()
class Card:
def __init__(self, card_number, user):
self.card_number = card_number
self.user = user
class Account:
def __init__(self, account_number, balance):
self.account_number = account_number
self.balance = balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
return True
return False
class Transaction:
def perform(self):
pass
class Withdrawal(Transaction):
def __init__(self, account, amount):
self.account = account
self.amount = amount
def perform(self):
if self.account.withdraw(self.amount):
return "Withdrawal Successful"
return "Insufficient Funds"
class Bank:
def validate_pin(self, card, pin):
# Logic to validate card and PIN
pass
SavingsAccount can replace the base Account class without altering behavior.Screen and Keypad focus on specific responsibilities.Transaction) rather than concrete classes.The design can handle additional features like: