TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Solid Is Not Solid – Examining the Single Responsibility Principle

3 点作者 reedlaw大约 5 年前

1 comment

reedlaw大约 5 年前
I like using the concept of Cohesion to answer questions about &quot;what belongs where&quot;. But I didn&#x27;t understand the conclusion. The author goes through two refactors of a Rails controller. After adding a call to a mailer he says:<p>&gt; Creating a widget and sending an email about it sound like they belong together, so I would argue this change doesn’t materially affect the cohesion of this class.<p>Then after adding a database statistic recorder:<p>&gt; The controller has nothing to do with databases, so this change feels like it reduces the cohesion of the class enough for us to question this change.<p>Finally the author concludes:<p>&gt; Yet in both cases, the Single Responsibility Principle has been violated. This tells me that framing the concept of cohesion as the Single Responsibility Principle is absolutely wrong.<p>How is it absolutely wrong when using cohesion as the paradigm agrees with SRP half the time?