Single Responsibility vs Separation of Concerns

I was thinking out loud the other day and was wondering what the difference between single responsibility and separation of concerns is. Are they similar at all?

Let’s go back to the basics and try to review both of what these two major principles st…

I was thinking out loud the other day and was wondering what the difference between single responsibility and separation of concerns is. Are they similar at all?

Let’s go back to the basics and try to review both of what these two major principles stand for.

Daria's responsible now



Single Responsibility

Single responsibility principle (S.R.P.) is one of the five principles of object oriented programming (O.O.P.). Does S.O.L.I.D. ring a bell? Well, it stands for the “S” in S.O.L.I.D. It’s an extremely useful thing to remember for early stage developers like myself. The end goal is always striving for maintainable code.

How does S.R.P. do this, you ask? It gives a function in a class only ONE reason to change, which is the sole responsibility that that function has. This in turn makes your code more modular.

Separate!!!



Separation of Concerns

Separation of Concerns (SoC) also known as Aspect-Oriented Programming is a design principle for separating programming into distinctive sections so each section addresses a specific concern.

Visualize a Model View Controller (MVC) pattern, if you will. Each section is divided by modules, and each module should be in charge of a task. With each module focusing on just one task, this makes the flow of data more efficient and again easy to maintain. This quick video gives you a better idea of what this actually means.

Diagram of MVC that visualizes modules



Conclusion

In a nutshell, the main difference between Single Responsibility Principle and Separation of Concerns is that SRP is isolated in a class in the form of one function, where as SoC is more spread out to how an MVC is structured.

Hope that gave you some clarity


Print Share Comment Cite Upload Translate
APA
Yani A. | Sciencx (2024-03-28T22:12:35+00:00) » Single Responsibility vs Separation of Concerns. Retrieved from https://www.scien.cx/2022/02/19/single-responsibility-vs-separation-of-concerns/.
MLA
" » Single Responsibility vs Separation of Concerns." Yani A. | Sciencx - Saturday February 19, 2022, https://www.scien.cx/2022/02/19/single-responsibility-vs-separation-of-concerns/
HARVARD
Yani A. | Sciencx Saturday February 19, 2022 » Single Responsibility vs Separation of Concerns., viewed 2024-03-28T22:12:35+00:00,<https://www.scien.cx/2022/02/19/single-responsibility-vs-separation-of-concerns/>
VANCOUVER
Yani A. | Sciencx - » Single Responsibility vs Separation of Concerns. [Internet]. [Accessed 2024-03-28T22:12:35+00:00]. Available from: https://www.scien.cx/2022/02/19/single-responsibility-vs-separation-of-concerns/
CHICAGO
" » Single Responsibility vs Separation of Concerns." Yani A. | Sciencx - Accessed 2024-03-28T22:12:35+00:00. https://www.scien.cx/2022/02/19/single-responsibility-vs-separation-of-concerns/
IEEE
" » Single Responsibility vs Separation of Concerns." Yani A. | Sciencx [Online]. Available: https://www.scien.cx/2022/02/19/single-responsibility-vs-separation-of-concerns/. [Accessed: 2024-03-28T22:12:35+00:00]
rf:citation
» Single Responsibility vs Separation of Concerns | Yani A. | Sciencx | https://www.scien.cx/2022/02/19/single-responsibility-vs-separation-of-concerns/ | 2024-03-28T22:12:35+00:00
https://github.com/addpipe/simple-recorderjs-demo