Difference between Single Responsibility Principle and Separation of Concerns

后端 未结 13 1366
-上瘾入骨i
-上瘾入骨i 2020-12-07 15:20

What is the difference between Single Responsibility Principle and Separation of Concerns?

相关标签:
13条回答
  • 2020-12-07 16:15

    I tried to draw a comparison between Separation of concerns(SoC) and Single Responsibility Principle(SRP).

    Differences

    • The SRP is at the class level, but SoC is in each computer program, abstraction ... or sometimes architectural level.

    • The SRP is about the quality of (how not what) dividing your domain into cohesive classes which have just one responsibility (one reason to change). In other side, SoC is a design principle for separating a context into distinct sections, such that each section addresses a separate concern(what not how), as there are a lot of tools (for example classes, functions, modules, packages, ...) to reach this goal different levels.

    • The concept of SRP is based on the cohesion (high cohesion), whereas SoC is close to Molecularity, divide and conquer (D&C), ... in each level of abstraction.

    • SoC is a good design principle to cope complexity, such as abstraction whereas to reach single responsible classes you can use SoC principle as a great solution. As, a way to know that a class has more than one responsibility is if you can extract another responsibility(concern) from that class.

    Similarities

    • After applying each of these principles, your context becomes more reusable, maintainable, robust, readable, ... .
    0 讨论(0)
提交回复
热议问题