Skip to content

Instantly share code, notes, and snippets.

View tauzen's full-sized avatar

Krzysztof Mioduszewski tauzen

View GitHub Profile
@tauzen
tauzen / money.py
Last active May 5, 2024 17:23
Python DDD - Value Object idea. Immutable attributes, methods, structural equality.
from collections import namedtuple
class Money(namedtuple('Money', ['amount', 'currency'])):
def add(self, amount):
return Money(self.amount + amount, self.currency)
m = Money(20, 'USD')
print(m)
# Money(amount=20, currency='USD')