liveBook · Manning

Business rule

As explained in Data-Oriented Programming in Java

A business rule is a domain constraint or policy that determines valid actions, states, or outcomes.

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

How Data-Oriented Programming in Java covers it

How deep it goes
Develops rules from ambiguous requirements through function-based invariants, sealed algebraic data, and dependency-level verification.
Examples
Uses late-fee billing, conflicting finance records, sales-account routing, rule algebra, and task lifecycle transitions.
What it assumes
Assumes intermediate Java while teaching rule modeling through records, sealed interfaces, functions, and tests.
What you can do after
Evaluate/understand whether rules are explicit, non-overlapping, composable, and enforced by the systems that must uphold them.
How it connects
Connects business rules to domain modeling, algebraic properties, sealed types, pattern matching, state machines, and integration testing.

Also explained in

Compare how 11 books explain business rule →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.