什么时候设计模式的问题而不是解决方案? [英] When are design patterns the problem instead of the solution?

查看:236
本文介绍了什么时候设计模式的问题而不是解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有使用过需要使用设计模式的软件。根据保罗·格雷厄姆的报复报导文章,设计模式是不够抽象的标志。

I’ve never worked on software where I needed to use design patterns. According to Paul Graham’s Revenge of the Nerds essay, design patterns are a sign of not enough abstraction.

直接引用他,例如,在OO世界,你听到很多关于模式的信息。我不知道这些模式是否有时候不是案例(c),人类编译器在工作中的证据。当我在程序中看到模式时,我认为这是一个麻烦的迹象。程序的形状只能反映需要解决的问题。代码中的任何其他规律都是一个标志,至少对我来说,我使用的抽象,
不够强大 - 通常我手工生成一些宏的扩展,我需要写。

To quote him directly, "For example, in the OO world you hear a good deal about "patterns". I wonder if these patterns are not sometimes evidence of case (c), the human compiler, at work. When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I'm using abstractions that aren't powerful enough-- often that I'm generating by hand the expansions of some macro that I need to write."

我只是想知道大家是否认为设计模式过度使用,并且代码中没有足够的抽象的症状。

I was just wondering if everyone thought design patterns are overused and are symptoms of not having enough abstraction in your code.

推荐答案

我不认为这些模式本身就是问题,而是开发人员可以学习模式,然后过度使用它们,或者以非常不合适

I don't think the patterns per se are the problem, but rather the fact that developers can learn patterns and then overapply them, or apply them in ways that are wildly inappropriate.

使用模式是经验丰富的程序员自然学习的东西。你已经解决了一些问题X很多次,你知道什么方法有效,你使用这种方法,因为你的技能和经验告诉你是适当的。这是一个模式,没关系。

The use of patterns is something that experienced programmers just learn naturally. You've solved some problem X many times, you know what approach works, you use that approach because your skill and experience tell you it's appropriate. That's a pattern, and it's okay.

但是,一个程序员同样有可能找到一种方法来做事情,并试图将他们遇到的每个问题都解决那个模具,因为他们不知道任何其他方式。这也是一种模式,它是邪恶的。

But it's equally possible for a programmer who's less skilled to find one way to do things and try to cram every problem they come across into that mold, because they don't know any other way. That's a pattern too, and it's evil.

这篇关于什么时候设计模式的问题而不是解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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