首先应该是什么——设计模式还是代码? [英] What should come first -- the design pattern or the code?

查看:36
本文介绍了首先应该是什么——设计模式还是代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始一个全新的项目——我应该查看我的规范并决定应用哪些设计模式,还是只是想出一个组织的总体概念并允许这些模式通过重构有机地出现?

I'm starting on a fresh new project--should I look at my spec and decide which design patterns to apply, or just come up with a general idea of organization and allow the patterns to emerge organically through refactoring?

根据您的经验,哪种技术最有效率并且更有可能产生干净优雅的代码?

In your experience, which technique will be most productive and have a greater chance of leading to clean elegant code?

我还想知道是否存在 GoF 未定义但可能同样有价值的设计模式?如果是这样,有哪些有用的资源可以让我了解这些?

I'm also wondering if there are design patterns out there that aren't defined by the GoF, but could be just as valuable? If so, what are some useful resources for informing myself about these?

推荐答案

您应该有机地发展您的代码,应用适合的模式.过早匹配模式可能会导致大量不合适的代码和过多的抽象层,从而使设计变得混乱.见证您所看到的任何在有人第一次发现模式后立即编写的代码 ;-)

You should grow your code organically, applying patterns as they fit. Matching up with patterns too early can lead to a lot of inappropriate code and so many layers of abstraction that the design becomes obfuscated. Witness any code you've seen that was written right after someone had discovered patterns for the first time ;-)

这篇关于首先应该是什么——设计模式还是代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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