Agent Wranglers

Coupling Recommended

Tell objects what to do

Give an object a command instead of reading its state and deciding for it. The rule that uses the data lives next to the data.

How to do it

When you see if (x.getStatus() === …) x.setStatus(…), move that decision into a method on x. The object then guards its own rules, and no caller can break them.

Example

// Bad: every caller must repeat the rule
if ($invoice->getStatus() === 'open' && $invoice->getDueDate() < $today) {
    $invoice->setStatus('overdue');
}

// Good: the invoice keeps its own rule
$invoice->markOverdueIfLate($today);
# Bad
if invoice.status == "open" and invoice.due_date < today:
    invoice.status = "overdue"

# Good
invoice.mark_overdue_if_late(today)

How to check

Reviewers fail code that reads an object's fields only to change the same object. Tests call the new method directly and cover every rule.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/coupling/tell-dont-ask.