我已经阅读了大约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)

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

其他回答

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

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

我发现,要理解或理解某些模式的好处有点困难,除非理解它们解决的问题和其他(更糟糕的)实现问题的方式。

除了GOF和POSA的书,我还没有真正读过,所以我不能给你其他的建议。实际上,您只需要了解问题领域,我认为许多缺乏经验的开发人员可能无法欣赏模式的好处。这不是对他们的轻视。当一个人不得不首先与糟糕的选择作斗争时,接受、理解和欣赏好的解决方案要容易得多。

祝你好运

设计模式只是工具——有点像库函数。如果你知道它们和它们的近似函数,你可以在需要的时候从书中找到它们。

设计模式并没有什么神奇之处,任何优秀的程序员都能在任何书籍问世之前自己找出90%的设计模式。在大多数情况下,我认为这些书在简单地为各种模式定义名称方面最有用,这样我们就可以更容易地讨论它们。

在我看来,阅读设计模式,练习编码的概念并没有真正的帮助。当你读这些书的时候。寻找特定设计模式解决的基本问题,从创建模式开始是最好的选择。2. 我相信你过去写过代码,分析一下你是否遇到了设计模式旨在提供解决方案的相同问题。3.尝试重新设计/重构代码,或者重新开始。

关于资源,你可以查看这些

www.dofactory.com 设计模式:可重用面向对象软件的元素(Addison-Wesley专业计算系列),作者:Erich Gamma、Richard Helm、Ralph Johnson和John M. Vlissides Martin Fowler的《企业应用程序体系结构模式》

1是快速入门,2是深入学习。第3节将解释或应该让你认为你在第2节中学到的东西适用于企业软件。

我的2美分…

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

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.