我已经阅读了大约4-5本关于设计模式的书籍,但我仍然觉得我在设计模式方面还没有接近中级水平?

我应该如何学习设计模式?

有关于设计模式的好书吗?

我知道这只会来的经验,但必须有一些方法来掌握这些?


当前回答

练习练习再练习。我认为4到5本书在没有大量练习的情况下是一种过度的阅读练习。我认为,做到这一点的最佳方法是开始使用这些模式重构您当前的项目。或者,如果你没有任何正在积极进行的项目,那么就按照你自己的方式来做,然后尝试重构模式。

如果你没有亲身经历过他们所解决的问题,你就无法充分欣赏他们。请记住,它们不是银弹——你不需要记住它们,并在飞行中努力应用它们。我的意见…

其他回答

对于这样一个老问题,我只有两分钱

有些人已经提到,实践和重构。我认为学习模式的正确顺序是:

学习测试驱动开发(TDD) 学习重构 学习模式

大多数人忽略了1,许多人相信他们可以做2,几乎每个人都直接去做3。

对我来说,提高软件技能的关键是学习TDD。这可能是一个痛苦而缓慢的编码过程,但首先编写测试肯定会让您对代码进行很多思考。如果一个类需要太多样板文件或者很容易崩溃,你很快就会注意到不好的味道

TDD的主要好处是你不再害怕重构你的代码,并迫使你编写高度独立和内聚的类。如果没有一套好的测试,触摸没有损坏的东西就太痛苦了。有了安全网,你将真正冒险对你的代码进行巨大的更改。这是你真正开始从实践中学习的时刻。

Now comes the point where you must read books about patterns, and to my opinion, it is a complete waste of time trying too hard. I only understood patterns really well after noticing I did something similar, or I could apply that to existing code. Without the safety tests, or habits of refactoring, I would have waited until a new project. The problem of using patterns in a fresh project is that you do not see how they impact or change a working code. I only understood a software pattern once I refactored my code into one of them, never when I introduced one fresh in my code.

我读了三本书,仍然不能很好地理解模式,直到我读了OReilly的Head First Design patterns。这本书让我大开眼界,解释得很清楚。

Derek Banas在youtube上制作了我非常喜欢的图案设计教程:

http://www.youtube.com/playlist?list=PLF206E906175C7E07

他们可能在时间上有点短,但他的时机和呈现方式使他们非常愉快地学习。

我的建议是组合实现其中的一些,并分析它们的一些实现。例如,在. net中,如果您查看数据适配器,就会发现有一些适配器模式的使用,如果稍微深入研究框架,还会发现其他一些适配器模式。

我认为您需要检查一些您作为开发人员遇到过的问题,当您因为另一个设计更改而不得不第十次修改代码时,您会感到非常紧张。你可能有一个项目清单,你觉得有很多返工和痛苦。

From that list you can derive the scenarios that the Design Patterns intend to solve. Has there been a time where you needed to perform the same series of actions on different sets of data? Will you need to be able to future capability to an application but want to avoid reworking all your logic for existing classes? Start with those scenarios and return to the catalog of patterns and their respective problems they are supposed to solve. You are likely to see some matches between the GoF and your library of projects.