liveBook · Manning

Separation of concerns

As explained in Learn Go with Pocket-Sized Projects

Separation of concerns is a design principle that assigns distinct responsibilities to separate software components.

Separation of concerns assigns distinct responsibilities to separate components. Give each package or structure a role that can be described in one sentence, while recognizing that excessive separation can create costly coupling. section 8.3

Apply the principle by:

  • Separating data fetching from data use so external-service logic can change without touching money conversion. section 6.5
  • Providing dependencies through contracts such as interfaces, allowing stubs during development and replacements such as caches later. section 6.5
  • Isolating storage management from API details, while accepting that some performance requirements may require them to evolve together. section 8.3

Splitting a Gordle service

Keep the session responsible for IDs, attempts, feedback history, and attempt limits. Keep the Gordle package responsible for creating games, evaluating guesses, and reporting whether a game is over. section 8.5

Table 8.2 Package requirements

Package session’s game

Package Gordle’s game

  • Stores the number of attempts left
  • Stores the list of attempts and feedbacks
  • Plays a guess by calling Gordle
  • Creates a game using a corpus for its solution
  • Accepts a guess and computes the feedback
  • Allows feedback to tell whether a game is over

Use the responsibility table to decide which state and behavior belong in the session or Gordle package. section 8.5

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains boundaries, contracts, replacements, and tradeoffs through money conversion and service-package examples.
Examples
Uses an exchange-rate API, stubs, caches, an in-memory repository, and separated Gordle session and game packages.
What it assumes
Assumes familiarity with packages, external dependencies, interfaces, APIs, and repositories.
What you can do after
Apply it by replacing dependencies, locating logic predictably, and testing evolving components independently.
How it connects
Connects to inversion of control, interfaces, repositories, API design, storage management, and hexagonal architecture.

Also explained in

Compare how 22 books explain separation of concerns →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.