当使用工厂模式? [英] When to use factory patterns?

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

问题描述

这是什么工厂一回事,什么是使用工厂模式的优势是什么?它是否给一个可插拔的体系结构?为什么它被称为工厂?

What is this factory all about and what are the advantages of using factory patterns? Does it give a plugable architecture? Why it is called "Factory"?

推荐答案

这是厂自它实际上是制造(创建)一个对象。

It is factory since it is actually "Manufacturing" (Create) an object.

实际上,有2种由GoF的定义工厂模式:

There's actually two kind of factory pattern defined by GoF:

  1. 工厂方法
  2. 抽象工厂
  1. Factory Method
  2. Abstract Factory

基本上他们都试图从知道实际的具体实现的类/接口的解耦调用客户端。

Basically both of them tries to decouple the calling client from knowing the actual concrete implementation of the class/interface.

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

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