什么时候使用工厂模式? [英] When to use factory patterns?

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

问题描述

这个工厂是做什么的,使用工厂模式有什么好处?它提供可插入的架构吗?为什么叫工厂"?

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.

实际上 GoF 定义了两种工厂模式:

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

  1. 工厂方法
  2. 抽象工厂

基本上,他们都试图将调用客户端与了解类/接口的实际具体实现分离.

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

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

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