Activator.CreateInstance和工厂有什么区别?它们可以互换使用吗?或者我们需要工厂模式吗? 工厂模式是更高级别的模式.它为您提供了一个结构,您可以在其中解决对象创建可能出现的一些
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将没问题.