且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单身真的有那么糟糕吗?

更新时间:2023-10-06 13:03:40

要记住的关键是设计模式只是帮助您理解抽象概念的工具.一旦你有了这样的理解,把自己限制在书中的食谱"上是没有意义的,并且会损害你编写最适合你的目的的代码的能力.

The key thing to remember is that design patterns are just a tool to help you understand the abstract concepts. Once you have that understanding, restricting yourself specifically to a "recipe" from a book is pointless and hurts your ability to write the code most appropriate for your purpose.

也就是说,阅读 GoF 之类的书籍会为您提供更多思考问题的方法,这样当需要自己实施某事时,您将有更广泛的视角来解决问题.

That said, reading books like GoF will present you with more ways to think about problems so that when the time comes to implement something on your own, you'll have a wider set of perspectives to approach the problem from.

在您的情况下,如果在每种情况下使用单例都有意义,那么请继续.如果它有点"适合并且您必须以某种笨拙的方式实施它,那么您需要提出一个新的解决方案.强迫一个不完美的模式有点像在圆孔中锤击方钉.

In your case, if using singleton makes sense in every case, then go right ahead. If it "sort of" fits and you have to implement it in some clunky way, then you need to come up with a new solution. Forcing a pattern that isn't perfect is somewhat like hammering a square peg in a round hole.

鉴于您说这种方法对我们的情况非常有效并且被证明非常实用",我认为您做得很好.

Given that you say "this approach has been effective and proven very practical to our circumstances," I think you're doing fine.

这里有一些好书:

四人帮 - 经典书籍用于设计模式

Gang of Four Book - the classic book for design patterns

Head First 设计模式 - 我已经听说有几个人推荐了这个作为替代方案

Head First Design Patterns - I've heard this recommended by a few people as an alternative