SOLID & Design Patterns Interview Question #134

What is separation of concerns?

Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios Senior Advanced

Quick Interview Answer

Separation of concerns divides software so different responsibilities are handled in appropriate components or layers. For example, controllers handle HTTP concerns, domain objects enforce business rules, and repositories or infrastructure components handle persistence.

Detailed Explanation

Separation of concerns divides software so different responsibilities are handled in appropriate components or layers. For example, controllers handle HTTP concerns, domain objects enforce business rules, and repositories or infrastructure components handle persistence.

Good separation reduces the number of reasons each component changes and limits the impact of modifications. Excessive fragmentation, however, can create needless navigation and indirection.

Code Example

Controller -> HTTP concerns
Application -> use-case orchestration
Domain -> business rules
Infrastructure -> database/external services