At Your Service

Saving Mr. Banks

Mi'kail Eli'yah
12 min read2 days ago

Let’s create a service to illustrate making a service with OO models. We can use an example of a banking application.

Create synthetic transaction components

This would include object components like Transaction, Account, and a Bank that uses these components.

# Record and hold transactions (deposits, withdrawals and transfers).

from datetime import datetime

class Transaction:
def __init__(self, transaction_id, amount, timestamp, transaction_type, account_id):
self.transaction_id = transaction_id
self.amount = amount
self.timestamp = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
self.transaction_type = transaction_type
self.account_id = account_id

def __str__(self):
return (f"Transaction(id={self.transaction_id}, amount={self.amount}, "
f"timestamp={self.timestamp}, type={self.transaction_type}, "
f"account_id={self.account_id})")

def __repr__(self):
return (f"Transaction(transaction_id={self.transaction_id}, amount={self.amount}, "
f"timestamp={self.timestamp}, type={self.transaction_type}, account_id={self.account_id})")


class Account:
def __init__(self, account_id):
self.account_id = account_id
self.balance = 0.0
self.transactions =…

--

--