Transaction script
One procedure per business operation that reads data, applies the rules and writes the result, with no domain model in between.
Fowler’s Transaction Script is the simplest way to organize business logic: “cancel visit” is a function that loads the visit, checks the rules and updates the row. It is easy to read and fast to write, and it fits well with vertical slices.
It stops scaling when rules grow and repeat across scripts; then a domain model with real objects pays off. DDD suggests the split: a rich model for the core domain, scripts for supporting areas. Scripts disguised as a domain model become an anemic domain model.
Sources
- Martin Fowler: Transaction Script martinfowler.com
- Martin Fowler: Domain Model martinfowler.com
Related terms
- Anemic domain model: Domain objects that only hold data with getters and setters, while all business rules live in service classes around them.
- Repository pattern: An object that looks like an in-memory collection of aggregates (add, find by ID, remove) and hides how they are stored.
- Core domain (subdomains): The part of the business that sets it apart from competitors; supporting and generic subdomains are the rest, which can stay simple or be bought.
- Vertical slice architecture: Organizing code by feature, with everything one use case needs (API, logic, data access and often UI) together, instead of by technical layer.
