工厂和策略设计模式有什么区别 [英] What is the difference between factory and strategy design pattern

查看:145
本文介绍了工厂和策略设计模式有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在学习设计模式.

我遇到了工厂和策略设计模式,它们看起来非常重叠并且在使用中很相似.

两种模式都使用"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: 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屋!

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