Behavior near state
The object that owns the state is often best positioned to make the decision.
Tell, Don’t Ask is a simple but powerful OOAD heuristic. Instead of pulling data out of an object and making decisions elsewhere, tell the object what outcome you need and let it decide how to act. The principle pushes behavior closer to the data and invariants it depends on.
In order-management domains, status transitions, inventory rules, refund eligibility, and shipment changes often leak outward into services. When that happens, objects become passive and services become procedural. Tell, Don’t Ask is one way to rebalance that responsibility.
Tell, Don’t Ask does not forbid querying data. It becomes important when decision logic depends on internal state and domain rules. In those cases, a richer object often produces a more cohesive and maintainable design.
In Java systems, this principle often distinguishes a richer domain model from an anemic one. The more critical the invariant, the more likely the object itself should be told to do the thing rather than asked for fields that outside code manipulates.
The principle works best where business meaning is central, not where the type is merely a data carrier.
The object that owns the state is often best positioned to make the decision.
Callers need less internal detail when they ask for outcomes rather than raw data.
Domain behavior becomes more central to the model instead of scattered across services.
package org.javaomnibus.ecommerce.principles;
import java.util.List;
public final class Order {
private final List lines;
private boolean submitted;
public Order(List lines) {
this.lines = List.copyOf(lines);
}
public void submit() {
if (lines.isEmpty()) {
throw new IllegalStateException("Order must contain at least one line");
}
this.submitted = true;
}
}
record OrderLine(String sku, int quantity) {}
Not every object should become rich with behavior. Simple boundary DTOs are still fine. The principle is strongest for domain types where correctness depends on internal state and rules.