Difference between Single Responsibility Principle and Separation of Concerns

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

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

13条回答
  •  旧时难觅i
    2020-12-07 15:56

    Separation of concerns (SoC). Divide your application into distinct features with as little overlap in functionality as possible. (Microsoft).

    “Concern” = “distinct feature” = “distinct section”

    “Concern” works at both high and low levels

    Single responsibility principle states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. (Wikipedia definition)

    “Responsibility” = “reason to change” change what? “a single part of the functionality provided by the software” = Basic Unit

    Conclusion

    • Single Responsibility Principle works on basic units -> works at low level

    • Separation of Concerns works at both high and low levels

    • SRP and SoC work together for separation of concerns. They are
      exactly the same at low level

提交回复
热议问题