Agent Wranglers

ARC-42Recommended

Give each module one reason to change

Each class, module or function serves one actor and has one reason to change.

How to do it

Name the person or team who would ask for a change. If a class answers to two, such as finance and the design team, split it. Keep calculation, storage and presentation apart. Keep the code for each feature in one folder, as Group code by feature says.

Examples

PHP example

// Bad: pricing, storage and email in one class
class OrderService {
    public function place(Order $order): void { /* price, save, send email */ }
}

// Good: one reason to change each
final class OrderPricer { public function total(Order $order): Money { /* ... */ } }
final class OrderRepository { public function save(Order $order): void { /* ... */ } }
final class OrderMailer { public function sendConfirmation(Order $order): void { /* ... */ } }

Python example

# Good: one reason to change each
class OrderPricer:
    def total(self, order: Order) -> Money: ...

class OrderRepository:
    def save(self, order: Order) -> None: ...

class OrderMailer:
    def send_confirmation(self, order: Order) -> None: ...

How to check

In review, describe the module in one sentence without "and". A linter limit on file size flags likely offenders, such as ESLint max-lines at 300 or PHPMD ExcessiveClassLength.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/solid-and-dry/single-responsibility">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.