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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Pattern vision

43 点作者 fogus超过 12 年前

3 条评论

pelle超过 12 年前
I see a lot of current libraries in the Ruby world taking this Patterns are law approach.<p>Particularly the Law of Demeter and the Single Responsibility Principle are frequent offenders.<p>You end up with something that could have been handled in one or two small classes and/or Concerns split up over 30 or so files neatly organized in a module hierarchy.<p>End result is that every single file has a single responsibility yet it's extremely difficult to see whats going on.<p>Rails 3 I think unintentionally started this. Through it's use of Concerns. This is good in a very large framework such as Rails and when the Concerns like in Rails contain a decent chunk of related code grouped together in one readable chunk.<p>I use Concerns within my own apps as well to maintain readable re useable code that can be used in multiple models.<p>If you have 20 Concerns each containing one or two methods split all over the file system it's difficult to maintain, but even harder to understand.<p>The Law of Demeter has also brought us ActiveModel wrapper classes that wrap all of this code together and when you add a column to the underlying table you can't use it with the wrapper class since it's not a real AR model. So you now have to fork the library or write your own models.<p>(edited to use the word Concern instead of the more generic Mixins)
评论 #4843104 未加载
raganwald超过 12 年前
I saw a tweet that sums it up: "Refactoring to patterns is far more important than designing with patterns."
评论 #4843068 未加载
mcgwiz超过 12 年前
tl;dr - patterns are seductive, and without understanding yagni, they strongly tend to be counterproductive.