加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Activator.CreateInstance vs Factory Pattern

发布时间:2020-12-16 01:35:19 所属栏目:百科 来源:网络整理
导读:Activator.CreateInstance和工厂有什么区别?它们可以互换使用吗?或者我们需要工厂模式吗? 解决方法 工厂模式是更高级别的模式.它为您提供了一个结构,您可以在其中解决对象创建可能出现的一些问题.引用 Wikipedia, The creation of an object often requir
Activator.CreateInstance和工厂有什么区别?它们可以互换使用吗?或者我们需要工厂模式吗?

解决方法

工厂模式是更高级别的模式.它为您提供了一个结构,您可以在其中解决对象创建可能出现的一些问题.引用 Wikipedia,

The creation of an object often
requires complex processes not
appropriate to include within a
composing object. The object’s
creation may lead to a significant
duplication of code,may require
information not accessible to the
composing object,may not provide a
sufficient level of abstraction,or
may otherwise not be part of the
composing object’s concerns.

Some of the processes required in the
creation of an object include
determining which object to create,
managing the lifetime of the object,
and managing specialized build-up and
tear-down concerns of the object.

Activator.CreateInstance不解决任何这些问题,它只允许您创建类型的新实例.如果您没有上述问题(并且“工厂模式”的许多用法不在此类问题的上下文中),Activator.CreateInstance将没问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读