separation of concerns vs loose coupling
Asked Answered
P

2

8

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.

Parkerparkhurst answered 16/5, 2012 at 14:17 Comment(2)
Instead of "Seperation of Concerns" do you mean Single Responsibility, as in this: en.wikipedia.org/wiki/SOLID_(object-oriented_design)Ricci
Check out this Question https://mcmap.net/q/263221/-what-is-an-example-of-the-single-responsibility-principle-closed/1158895Ricci
B
12

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.

Bashful answered 16/5, 2012 at 14:20 Comment(3)
Exactly. Maybe instead of Coupling, @Parkerparkhurst wanted to refer to Cohesion.Ricci
Then yes, coding by separating of concerns increases cohesion of your codeBashful
You can't have a loosely coupled system if you don't have a separation of concerns, but a separation of concerns doesn't guarantee a loosely coupled system.Philbrook
E
7

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.

Eberta answered 16/5, 2012 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.