工厂方法模式的实际用途是什么? [英] What are the practical uses of Factory Method Pattern?

查看:168
本文介绍了工厂方法模式的实际用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的设计模式。我刚刚遇到工厂设计模式。我理解它将实例化委托给子类。但是我没有得到模式的实际应用。在哪种情况下,这种模式可以用于很好的效果。我听说过模式滥用,不想沉迷于此。任何人都可以提到通常使用的真实世界的例子。

解决方案

我已经将它用于插件到应用程序...这样你可以让你的主要应用程序调用类工厂实例化您在主应用程序中开发的某些界面的特定插件。这样,您可以编写应用程序的主要部分,而无需知道要插入的内容。


I'm pretty new to Design Patterns.I just came across Factory Design Pattern. I understood that it delegates the instantiation to subclasses. But I didn't get the actual application of the pattern. In which scenarios can this pattern be used to good effect. I've heard of pattern abuse and would not like to indulge in that. Can anyone mention a real world example where it is commonly used.

解决方案

I've used it for plugins to applications... this way you can have your main application call the class factory to instantiate the specific plugin implementing some interface that you've developed to in your main app. This way, you can code the main portion of your application without ever needing to know what is going to be plugged in.

这篇关于工厂方法模式的实际用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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