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

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

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

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


当前回答

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)

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

其他回答

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

对于初学者来说,头部优先设计模式就可以了,一旦我们熟悉了所有的模式,然后尝试将实时对象可视化到这些模式中。

本书将帮助你理解基本概念,除非你已经在现实世界中实现了,否则你不能成为设计模式的大师

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)

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

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

我推荐HeadFirst DesignPattern。阅读书本是不够的,在吸收了这些概念之后,你需要为你脑海中出现的许多问题找到答案,并试图找出这些模式在现实生活中的应用。我也在做同样的事情,开始问问题,即使这些问题看起来很傻。