你怎么知道什么时候使用设计模式? [英] How do you know when to use design patterns?

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

问题描述

任何人都可以阅读GoF书,了解什么样的设计模式以及如何使用它们,但是在设计模式解决问题的时候,有什么过程呢?这种模式的知识是否驱动了设计,还是有一种方法来确定如何使用模式来更改设计?



换句话说,是否有

解决方案

设计模式应该提供一种可以解决问题的结构 。解决一个真正的问题时,您必须考虑到这个问题的解决方案的许多微小变体,看看是否符合设计模式。特别是,您可能需要概括您的问题或其解决方案,以使设计模式适合。



答案是,这是一门艺术。知道设计模式当然是重要的一步。习惯这种事情的一个方法是研究设计模式的应用程序,而不仅仅是模式。看到一个模式的许多不同的应用程序可以帮助你随着时间的推移,将任务映射到一个模式上。


Anyone can read the GoF book to learn what design patterns are and how to use them, but what is the process for figuring out when a design pattern solves a problem? Does the knowledge of the pattern drive the design, or is there a way to figure out how a pattern can be used to change a design?

In other words, are there patterns for Patterns?

解决方案

Design patterns are supposed to provide a structure in which problems can be solved. When solving a real problem, you have to consider many tiny variations of a solution to that problem to see whether any fits a design pattern. In particular, you will probably need to generalise your problem, or its solution, in order to make a design pattern fit.

The answer is, it's an art. Knowing the design patterns is certainly an important step. One way to get used to this sort of thing is to study applications of design patterns, not just the patterns. Seeing many different applications of one pattern can help you over time to get better at mapping a task onto a pattern.

这篇关于你怎么知道什么时候使用设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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