Last active
May 25, 2025 19:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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