工厂和策略设计模式有什么区别 [英] What is the difference between factory and strategy design pattern
问题描述
我正在学习设计模式.
我遇到了工厂和策略设计模式,它们看起来非常重叠并且在使用中很相似.
两种模式都使用"new"关键字来返回对象(工厂)或return和算法(策略).
在概念上似乎不同,工厂用于相似类组的不同实例化.其中,如Strategy用于在算法之间进行切换.但是当我一起查看它们的示例时,它们看起来非常相似.
谁能帮我举一个合适的例子来区分它们及其正确用法.
在此先感谢.
Hi,
I am learning design patterns.
I came across factory and strategy design pattern which looks quite overlapping and similar in use.
Both patterns use "new" keyword to return an object(factory) or return and algorithm(strategy).
Conceptually it seems different, factory is used for differed instantiation of similar group of classes. where as Strategy is used for switching between algorithms. But when i see their examples together, they look quite similar.
Can anyone help me with a suitable example to differentiate them and their proper usage.
Thanks in advance.
推荐答案
甚至在 ^ ].
Google: ^ ]
您也可以在Google以及CodeProject上分别进行搜索.尝试看看其他示例(不确定您在谈论哪个示例!).如果您仍然感到困惑,请发布相关代码段,并发布与困惑有关的特定问题.您越清晰和具体,就越能期望得到更好的响应-这将最终帮助您更清楚地了解事物.
Google: Search result[^]
You can also search them individually both on Google as well as on CodeProject. Try to look at other examples (not sure of which one you are talking of!). If you are still confused then post related code snippets and post specific question related to the confusion you have. The more clear and specific you are, better the response you can expect - it would help you at the end to understand things more clearer.
这篇关于工厂和策略设计模式有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!