A codebase can become a junk drawer: change a button label, and payment logic breaks. Separation of concerns (SoC) aims for a toolbox instead. Divide a system into distinct parts, each with a well-defined responsibility and a boundary that says what it should—and should not—do. section 3.2 section 1.5.4
The parts still work together. For an article-favorite button, the UI handles the click and display state, coordinating logic checks the user and requests an update, and the data part stores the user–article relationship. Keeping those jobs apart makes the system easier to navigate, test, and change. section 1.5.4 section 2.3
Untangling order processing
A single order-processing method mixes validation, payment, inventory, and email. A clearer design gives each job a focused service and uses an OrderService to coordinate them. Splitting the method into private helpers is quicker and improves readability, but leaves the core responsibility and testability problems in place. Separate services take more upfront work. section 3.5.2 section 3.5.3
Listing 3.15 “After” High-Level Coordinator Class
// This high-level class coordinates the work.
class OrderService {
// Dependencies are "injected" through the constructor
constructor(validator, paymentService, inventoryManager,
notificationService) {
this.validator = validator;
this.paymentService = paymentService;
this.inventoryManager = inventoryManager;
this.notificationService = notificationService;
}
processOrder(order) {
this.validator.validate(order);
if (this.paymentService.processPayment(order)) {
this.inventoryManager.updateInventory(order);
this.notificationService.sendConfirmationEmail(order);
return "Order processed successfully.";
} else {
return "Payment failed.";
}
}
}See how the coordinator receives its services and directs the order workflow without taking over their individual jobs. section 3.5.3
The same idea works at different scales: a focused method, a cohesive class, or a system of separate components. Layered architecture applies it across an application. Cross-cutting concerns need boundaries too: logging can be an injected dependency rather than a job embedded in business logic. section 3.7 section 4.10 section 4.5.3
Separation also helps when the network misbehaves. Keep the business job of fetching data apart from retries and backoff; resilience libraries can wrap fragile calls without putting retry loops throughout business logic. A direct payment API call tangled into checkout makes testing dependent on the network and makes changing providers more disruptive. section 10.4 section 10.4.1
Try a quick boundary check:
- Name the one job of a method or class. If its description needs “and,” look for responsibilities that could be separated. section 3.2
- Sketch the responsibilities as boxes and identify who coordinates them before choosing an implementation. section 3.5.2
- Ask how you would unit-test each part and where a likely change would land. Complicated tests or unrelated changes are clues to tangled boundaries. section 3.4.6
























