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

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

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

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


当前回答

我领导了一些设计模式讨论小组(我们的网站),并阅读了5或6本模式书籍。我建议从《头部优先设计模式》一书开始,参加或发起一个讨论小组。《Head First》一开始可能看起来有点像Hasboro,但大多数人在读了一两章后就喜欢上了它。

Use the outstanding resource - Joshua Kereivisky's A Learning Guide to Design Patterns for the pattern ordering and to help your discussion group. Out of experience the one change I suggest to the ordering is to put Strategy first. Most of today's developers have experienced some good or bad incarnation of a Factory, so starting with Factory can lead to a lot of conversation and confusion about the pattern.This tends to take focus off how to study and learn patterns which is pretty essential at that first meeting.

其他回答

最好的方法就是用它们开始编码。设计模式是一个伟大的概念,仅仅通过阅读很难应用它们。从网上找到一些示例实现,然后围绕它们进行构建。

数据和对象工厂页面是一个很好的资源。他们会讲解这些模式,并给出概念上和现实世界中的例子。他们的参考资料也很棒。

The way I learned design patterns is by writing lots of really terrible software. When I was about 12, I have no idea what was good or bad. I just wrote piles of spaghetti code. Over the next 10 years or so, I learned from my mistakes. I discovered what worked and what didn't. I independently invented most of the common design patterns, so when I first heard what design patterns were, I was very excited to learn about them, then very disappointed that it was just a collection of names for things that I already knew intuitively. (that joke about teaching yourself C++ in 10 years isn't actually a joke)

这个故事的寓意是:编写大量的代码。就像别人说的,练习,练习,再练习。我认为,在您了解当前的设计为什么不好并寻找更好的方法之前,您不会很好地了解在哪里应用各种设计模式。设计模式书应该为您提供完善的解决方案和与其他开发人员讨论的通用术语,而不是对您不理解的问题的粘贴解决方案。

你试过《四人帮》这本书吗?

设计模式:可重用面向对象软件的元素

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

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

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

有很多很好的例子。我想补充一点:

误用。您不需要故意这样做,当您尝试在初始设计模式匹配中应用它们时,就会发生这种情况。在此期间,您将看到的每个问题似乎都恰好符合一种设计模式。通常,由于某些原因,所有问题似乎都符合相同的设计模式(Singelton是主要的候选)。

你应用这个模式就会很好。几个月后,您将需要更改代码中的某些内容,并发现使用特定的模式并不明智,因为您将自己编码到一个角落,您需要再次重构。

当然,这并不是一个真正的“做了就会在21天内学会”的答案,但以我的经验来看,这是最有可能让你对问题有一个很好的洞察的答案。