设计模式列表仅适用于静态类型语言而不适用于动态类型语言?
有人知道仅适用于静态类型语言但不适用于动态类型语言的设计模式列表吗?
例如策略
Anyone know a list of design pattern only applicable to static typing language but not dynamic typing language?
E.g. strategy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设计模式有两个方面:职责划分,以改进程序结构、实现灵活性和易于维护。以及一组特定于语言的构造来实现该模式。在某些情况下,我们通过巧妙的设计来补充语言的自然功能。
策略模式在此处描述为
现在,这种将客户端与实现细节解耦的设计目标肯定适用于动态语言和静态语言。
细节有所不同,因为静态语言导致我们声明显式接口并对客户端进行编码以使用接口,而动态语言可以使用“鸭子类型”,但编码来处理在预期鸭子的地方接收狮子。 (animal->eat() ...不不!不要吃我!)
我期望看到动态代码中大多数设计模式的示例,这些示例可能以不同的方式表示 - 相同的关注点分离仍然很重要。
There are two aspects to a design pattern: a partitioning of responsibilities in order to improve program structure, enable flexibility and ease maintenance. And a language-specific set of constructs to implement that pattern. In some cases we are supplementing the language's natural capabilities with cunning design.
Strategy pattern is described here as
Now this design goal of decoupling clients from the specifics of implementation is surely applicable in dynamic languages as well as static languages.
The details vary because Static languages lead us to declare explicit Interfaces and code the clients to use interfaces while dynamic languages can use "Duck Typing" but coding to deal with receiving lions where ducks were expected. (animal->eat() ... no no! not eat me!)
I'm expecting to see examples of most design patterns in dynamic code possibly represented rather differently - the same separations of concerns are still important.