liveBook · Manning

Coupling

As explained in 100 Go Mistakes and How to Avoid Them

A software design technique that reduces direct dependencies between components so implementations can change independently.

Coupling describes how directly one component depends on another. Loose coupling replaces concrete implementations with focused abstractions, allowing implementations to change without changing dependent code. section 2.5.2

Interfaces reduce coupling when they express the dependency a component actually needs:

  • Depend on common behavior rather than a concrete type, as sort.Interface does for collection sorting. section 2.5.2

Error wrapping can create coupling

Returning fmt.Errorf("bar failed: %w", err) preserves the source error for callers, so callers may couple themselves to its type. If that source error is an implementation detail, fmt.Errorf("bar failed: %v", err) adds context while transforming it and making unwrapping unavailable. section 7.2

How 100 Go Mistakes and How to Avoid Them covers it

How deep it goes
Explains interface selection through concrete cases and traces error-wrapping consequences, without developing broader coupling theory.
Examples
Uses sort.Interface, CustomerService storage, restricted configuration getters, and fmt.Errorf with %w or %v.
What you can do after
Apply it via Go interfaces and deliberate error handling to replace implementations or hide unstable error details.
How it connects
Connects interfaces, abstraction, the Liskov Substitution Principle, error wrapping, and error transformation.

Also explained in

Compare how 17 books explain coupling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Go Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.