Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active May 25, 2025 19:53
Show Gist options
  • Save mcsee/71ac6c405062a1238a4015d44797ca7c to your computer and use it in GitHub Desktop.
Save mcsee/71ac6c405062a1238a4015d44797ca7c to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
class InvoiceProcessor:
def __init__(self, billing_ledger):
self.billing_ledger = billing_ledger
def process_invoice(self, customer, amount):
# Pure business logic with proper domain objects
if customer.credit_limit < amount:
raise CreditLimitExceededException()
# Business calculations
tax = amount * 0.21
total = amount + tax
# Create the domain object
# No repositories are involved
invoice = Invoice(
customer=customer,
amount=amount,
tax=tax,
total=total
)
self.billing_ledger.record(invoice)
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment