.Net 模式与 GOF
由于 GOF 书是在 .Net 出现之前就编写完成的,那么 GOF 中描述的特定模式是否有不适合 .Net 的地方?如果是这样,原因是什么?
这是一个与最近的赏金讨论相关的问题。
Since the GOF book was put together well before .Net came into being, are there any specific patterns described in GOF that are not appropriate for .Net? And if so, for what reason?
This is a question relating to a recent bounty discussion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
GoF 书的想法并不是针对特定语言,尽管他们确实提供了示例来更好地解释设计。
这个想法是提供在软件设计中一次又一次出现的模式,以及一本食谱,任何开发人员都可以根据需要用他们选择的语言来实现这些模式。
也就是说,当您查看 .NET 时,正如其他人所提到的,您将看到一些设计模式在框架中作为一等公民实现。
是否存在因语言而“无用”的情况?不会。即使某些模式已经为您实现,这些模式仍将继续有用。
The idea with the GoF book wasn't to be language-specific, although they did provide samples to better explain the designs.
The idea was to provide patterns which appear again and again in software design, and something of a cookbook that any developer can use to implement those patterns as needed in their language of choice.
That said, when you look at .NET, as others have mentioned, you will see several of the design patterns implemented as first-class citizens right in the framework.
Are there any "not of use" because of a language? No. The patterns will continue to be useful, even if some are already implemented for you.
C# 3.0 设计模式一书讨论了 .NET 上下文中的原始设计模式。在我看来,它不如原书,但仍然值得一读。
The book C# 3.0 Design Patterns discusses the original design patterns in a .NET context. It is not as good as the original book IMO, but still worth a read.
嗯,有些用途有限,因为它们已经在框架中实现了。
例如,.NET 中的集合已经支持开箱即用的迭代,因此在大多数情况下您不需要实现迭代器模式。另一个例子是事件,可以使用它来代替自己实现观察者模式。
Well, some have limited use because they are already implemented in the framework.
For example, collections in .NET already support iteration out-of-the-box, so you wouldn't need to implement the Iterator pattern in most cases. Another example is Events which can be used instead of implementing the Observer pattern yourself.
一般来说,GoF 模式往往适用于面向对象的语言,更具体地说,适用于强类型语言或具有更严格限制的语言。
The GoF patterns tend to apply, in general, to object-oriented languages and, more specifically, to strongly typed languages or to languages with more severe strictures.
不。
即使是 .NET(事件)中的一等公民 Observer 也有其用途,正如最近的 Rx 框架所展示的那样。
No.
Even the Observer which is a first class citizen in .NET (events) has it's uses as the recent Rx Framework shows.