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.
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.
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.
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.
Top comments (0)