separation of concerns vs loose coupling

4k views Asked by At

I would like to understand the difference between separation of concerns and loose coupling.

Is it true that coding by separation of concerns gives a loosely coupled code?

Thank you.

2

There are 2 answers

3
Sergey Berezovskiy On BEST ANSWER

Coupling is about how much each component knows about other components.

Separation of concerns is about separating different aspects of functionality in different components. You can separate different aspects, but make components tight coupled (i.e. use concrete classes instead of abstractions).

UPDATE: cohesion shows how closely-related responsibilities of component. When you separate different concerns in different components, then responsibilities of component are strongly-related, thus you have high cohesion.

0
Brian Geihsler On

A helpful way to think about this is that separation of concerns dictates what each class/function should do, and coupling dictates how much these classes/functions know about each other.

Separation of concerns is related to the Single Responsibility Principle, which says that each component in your system should only be responsible for one thing.

The amount of coupling in your system relates to how each of these components talk to each other. Do they have strong knowledge of each other (tight coupling) or is their knowledge of each other abstracted away via interfaces/functional bindings/etc (loose coupling)? Loose coupling typically makes a system easier to change because changing one piece of the system doesn't affect the other components.