Activator.CreateInstance vs Factory Template

What is the difference between Activator.CreateInstance and factory? Can they be used interchangeably? Or do we need a factory template?

+3
source share
2 answers

The factory sample is a higher level template. This gives you a structure in which you can solve some problems that may arise when creating an object. Quote from Wikipedia ,

Creating an object often requires complex processes, and it is not advisable to include it in the component object. Object creation can lead to significant duplication of code, information that is not available to the component object may be required, it may not provide a sufficient level of abstraction, or otherwise component objects cannot be part.

Some of the processes required in creating an object include determining which object to create by managing the lifetime of the object, and managing specialized build-ups and disrupting the problems of the object.

Activator.CreateInstance does not address any of these issues, it just allows you to create a new instance of the type. Unless you have problems like the above (and many uses of the factory template are not related to such problems), Activator.CreateInstance will be fine.

+3

Activator.CreateInstance , .

factory pattern () , .

"" Activator.CreateInstance factory . . . factory, Activator.CreateInstance

+4

Source: https://habr.com/ru/post/1739976/


All Articles