设计模式真的是语言的弱点吗? [英] Are design patterns really language weaknesses?

查看:144
本文介绍了设计模式真的是语言的弱点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果今天的模式被视为Java和C ++中的缺陷或缺少的功能


  • 子程序是五十和六十年代机器语言的设计模式。

  • 面向对象类是70年代C的设计模式。

  • 访问者,抽象工厂,装饰器和外墙是当今Java和C ++的设计模式。

  • Subroutine was a design pattern for machine language in the 50s and 60s.
  • Object-Oriented Class was a design pattern for C in the 70s.
  • Visitors, Abstract Factories, Decorators, and Façades are design patterns for Java and C++ today.

明天的语言会是什么样子?

What will tomorrow's languages look like? What patterns will they have?

推荐答案

一些封装的设计模式 - 适配器,工厂,命令,访问者等 - 是将其烧制成其他语言的功能的近似值。我的头顶部:

Some canonized design patterns -- Adapter, Factory, Command, Visitor, etc -- are approximations of features which are baked into other languages. Off the top of my head:


  • C#中的事件处理程序是烘焙版本的观察者模式。考虑如何在C#中连接事件,如果每次都要滚动自己的观察者。

  • Event-handlers in C# are baked-in versions of the observer pattern. Think about how you'd wire up events in C# if you had to roll your own observer each time.

访问者模式是一个详细的近似值 multimethods 邮件转发,或者一个非常弱的形式的模式匹配

Visitor pattern is a verbose approximation of multimethods, message forwarding, or a really weak form of pattern matching.

命令模式包装一个特定的行为,以便您可以传递对象方法之间或多或少地接近一级函数。

Command pattern wraps up a particular behavior so you can pass the object between methods, which more or less approximates first-class functions.

策略模式允许您动态地将一个行为插入到一个对象中,以便随时你可以通过与另一个交换一个行为来修改对象。在功能编程世界中,我们称之为功能组合。

Strategy pattern allows you to dynamically insert a behavior into an object, so that at any time you can modify the object by swapping out one behavior with another. In the functional programming world, we call this function composition.

抽象工厂模式接受一个参数并返回一个工厂。一般来说,您可以将工厂视为基本的包装函数(更具体地说,围绕构造函数的包装)。所以,你传递参数到一个函数并获得一个功能,使这个模式非常类似于currying。

Abstract factory pattern accepts an argument and returns a factory as a result. In general, you can think of factories as basically wrappers around a function (more specifically, wrappers around a constructor). So, you pass arguments to a function and get a function as a result, making this pattern pretty analogous to currying.

装饰器模式允许你附加或删除在运行时对对象的行为。在JavaScript中,您可以添加或删除函数,而不需要明确地实现装饰器模式,这要归功于原型OO模型。

Decorator pattern allows you to attach or remove behaviors to an object at runtime. In JavaScript, you can add or remove functions without explicitly implementing the decorator pattern thanks to the "prototype" OO model.

所以,我们有一堆模仿其他语言固有特征的设计模式。特色羡慕并不一定表示这种语言的弱点 - 它是您需要一次又一遍地编写的样板代码,这表示语言的弱点。

So, we have a bunch of design patterns which emulate features intrinsic to other languages. Feature envy doesn't necessarily indicate a weakness in the language -- it's the boilerplate code that you need to write over and over and over which indicates the language weakness.

这篇关于设计模式真的是语言的弱点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆