What is the difference between Activator.CreateInstance and factory? Can they be used interchangeably? Or stil do we need a factory pattern?
What is the difference between Activator.CreateInstance and factory? Can they be used interchangeably? Or
Share
The factory pattern is a higher-level pattern. It gives you a structure in which you can address some issues that can occur with object creation. To quote from Wikipedia,
Activator.CreateInstance doesn’t address any of these issues, it merely allows you to create a new instance of a type. If you don’t have issues like the above (and many uses of the “factory pattern” aren’t in the context of such issues), Activator.CreateInstance will be fine.