Is “high cohesion” a synonym for the “Single Responsibility Principle?”

前端 未结 4 603
旧巷少年郎
旧巷少年郎 2021-02-05 09:10

Is high cohesion a synonym for the Single Responsibility Principle? If not, how are they different?

4条回答
  •  旧巷少年郎
    2021-02-05 09:46

    It's not a synonym. SRP (Single Responsibility Principle) is when you ensure yours classes will have only one responsibility. For sure this increases your classes cohesion.

    But you can have high cohesion without following SRP to the letter.

    Here is a good source on that.

提交回复
热议问题