Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 19, 2022 12:33 am GMT

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 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


Original Link: https://dev.to/yani82/single-responsibility-vs-separation-of-concerns-5amh

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To