Separation of concerns
Разделение ответственности
A design principle that keeps different jobs in different parts of a program. For example, code that decides what to charge can be separate from code that displays the price.
Also known as: SoC
What counts as a concern?
A concern is a distinct job the software has to do, such as applying a business rule, saving a record, or displaying a result. Separation of concerns (SoC) means drawing boundaries so that the code for one job does not need to know the details of another. The payoff is concrete: a change to how a receipt looks should not require editing the rules that determine its total.
Example: overdue books
Suppose a library app shows an overdue badge. It needs to decide whether a loan is overdue, then decide what to display. Those decisions can live in separate functions:
def is_overdue(due_on, today):
return today > due_on
def loan_badge(overdue):
return 'Overdue' if overdue else 'On time'
The badge takes the result of the rule instead of comparing dates itself. A reminder job can reuse is_overdue without rendering anything. Passing today explicitly also makes it easy to test the boundary: a book due today is not overdue under this rule. If the library adds a grace period, change the rule. If the product team wants different wording, change the badge.
Where to draw the boundary
Look for decisions that change for different reasons. In a web app, request parsing changes with the API, business rules change with product requirements, and database queries change with storage needs. A handler can translate the incoming request into inputs for the application logic, then translate its result back into a response. The application logic need not understand HTTP to do its job.
Separation does not mean the parts never talk. It means they communicate through a clear contract without reaching into each other's internals. SoC works at the scale of functions, modules, or whole subsystems; none of those boundaries requires a network call. A single deployable application can have well-separated concerns.
Common mistakes
Moving code into different folders is not enough. If a UI component still looks up a loan in the database and decides whether it is overdue, renaming the file won't separate those jobs. The opposite mistake is adding layers that only forward calls. Keep code that belongs to the same decision together, and add a boundary where it makes a real change or test simpler.
The single responsibility principle (SRP) is closely related, but asks a narrower question: what reasons does this particular module have to change? SoC is the broader idea of keeping distinct jobs apart across a design.
How it comes up in interviews
You may be asked to refactor an endpoint that validates input, applies a discount, and saves an order. Explain which checks are about the request format and which are business rules, what data crosses each boundary, and how you would test the discount without a running database. Walking through one likely change is more useful than reciting a list of layers.