
Designing a Domain Model That Actually Models the Domain
Ports and adapters only work if you have a domain worth protecting. If your domain objects are just bags of getters and setters no behavior, no rules, no real logic the boundaries don't buy you much. You've built a clean fence around an empty lot. This post is about filling the lot. The Anemic Domain Model Here's the Order and Customer you see in most codebases even the "clean" ones: from dataclasses import dataclass from typing import List , Optional @dataclass class OrderItem : product_id : str price : float quantity : int @dataclass class Customer : id : str loyalty_points : int @dataclass class Order : customer_id : str items : List [ OrderItem ] loyalty_points : int total : float = 0.0 status : str = " draft " id : Optional [ str ] = None These are data containers. They hold values. They don't do anything. The business rules that involve these objects how totals are calculated, what makes an order valid, whether a customer qualifies for a discount live somewhere else. Usually scat
Continue reading on Dev.to Python
Opens in a new tab



