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

前端 未结 4 678
旧巷少年郎
旧巷少年郎 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:50

    In Robert Martin's own words,

    If you think about [SRP] you’ll realize that this is just another way to define cohesion and coupling. We want to increase the cohesion between things that change for the same reasons, and we want to decrease the coupling between those things that change for different reasons.

    See also: Difference between Single Responsibility Principle and Separation of Concerns.

提交回复
热议问题