Coupling
Let each module talk only to its direct neighbours. Make the order of calls impossible to get wrong, share no global state and hide the rest.
- Required 3
- Recommended 2
Required
Talk only to your direct neighbours
RequiredA function calls methods on its own object, its arguments and the objects it creates. It never reaches through one object to steer another, as in
a.getB().getC().doSomething().Make the order of calls impossible to get wrong
RequiredIf methods must run in a set order, the code must enforce it. Never rely on callers remembering to call
init()first.Pass state in instead of sharing globals
RequiredNever share changeable data through globals, singletons or module-level variables when it changes how code behaves. Pass state in, and return new state out.
Recommended
Tell objects what to do
RecommendedGive an object a command instead of reading its state and deciding for it. The rule that uses the data lives next to the data.
Keep internals private
RecommendedEach module exports only what its callers need. Everything else stays private, so it can change without breaking anyone.
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.