A business rule states what actions, states, or outcomes are valid in a domain. Make that meaning explicit rather than hiding it in null checks, vague flags, or runtime defenses. A billing operation that accepts any invoice but quietly rejects most of them advertises the wrong contract; model the narrow set of chargeable invoices so misuse is difficult or impossible. section 5.2
Rules also resolve ambiguity. When upstream finance records conflict or omit values, a policy such as “favor not billing the customer” supplies a domain basis for choosing data, instead of letting incidental implementation details decide. section 7.1
Account-routing rules
A sales organization may be chosen by overlapping-looking conditions: region, sector, country, segment, and channel. Model only the account attributes needed for routing, with enums and small record types that give each value a clear business meaning. section 8.1
For a rule set that maps accounts to sales organizations, correctness can be global: each rule may cover many accounts, but rules must not share outputs or inputs. Treating rules as functions makes those non-overlap invariants testable across the whole set. section 8.1.1
Listing 8.14 The finished algebra
sealed interface Rule {
record Equals(Attribute field, String value) implements Rule {}
record And(Rule a, Rule b) implements Rule {}
record Or(Rule a, Rule b) implements Rule {}
record Not(Rule rule) implements Rule {}
}A sealed rule algebra makes equality, conjunction, disjunction, and negation visible as domain data rather than dispersed control flow. section 8.4
Once rules are data, they can be composed, transformed, and eventually interpreted. AND, OR, and NOT become explicit constructors; convenience methods can retain readable fluent expressions without losing the underlying structure. section 8.4
State-transition constraints
A task begins as Started and may reach Completed or Failed. Database constraints must enforce that new writes are allowed, states are immutable, and terminal states cannot transition further; expressing the lifecycle as an ordering supports tests against the real dependency. section 12.3










