Do “Separation of concerns”


I understood(edit: I assume) the importance of seperation of concerns and benifits in an application, But struggling to identify what are considered to be a concern (developer, feature, consumer or what ?).

I found this in stack overflow for what is SoC
One example might be a html developer might want to separate out html, css and javascript into separate files.

In the above idea of SoC, They're seperating based on languages, So they assume language are the concern, But in the context of react JSX and JS and sometimess CSS will be on same file here we set component as concern.

Lets say i have feature user management where it comes with
Add User
Remove, Update User…

For this feature i have to make service classes right ?
As user is core feature of my application, It exposes variety of functionalities like user crud operations, authurisation services etc..

in this situation a single service named cant pack all the service, So how do i seperate the single service into multiple

My ideas were

  • Seperating based on operation—–>,, …
  • Seperating based on consumer
    ——->,, …

Both seems valide seperation, How to identify which seperation suits my development.

I tried to identify which seperation suits the best in consumer pov, but cant figure out which is best,

The answer may be like it deponds on the service and use cases, If so what are the seperation concern grouping are working in long run in a java based monolithic backend development.

Best Answer

Most design practices have one goal in mind - maintenance.

When a component is changed it may become buggy. To minimize bugs we want each change to affect less components (we assume that a in a well designed system, bugs in one component do not affect other components, which is not a given). For a change to affect less components, components should be split in a way, that each potential change would affect only one. Predicting future changes is in general impossible, but there are some heuristics that help. SoC is an example of such heuristic - it dictates, that a change of requirements usually involves only one business process or entity or technical aspect. The conclusion is then that components should be split along business entity seams.

Unfortunately it does not work particularly well, because business entities and technical aspects are ill defined and inexact. Therefore SoC is not a particularly good heuristic most of the time.

SoC is very good for:

  • data access layer, because persistence is usually a well-defined concern
  • domain model isolation - because it often clear where business ends and infrastructure starts
  • etc

Somewhat less good for:

  • Presentation (UI)
  • Scheduling
  • etc

Awful for:

  • Domain splitting
  • etc

As it basically breaks down to a bunch of isolated cases, it is never a safe bet to talk about SoC in abstract, talking about specific case like separation of DAL from your business logic is much more effective (clear).

Just predict the future.

Related Topic