How can I prevents objects being instantiated except in a defined 'factory class'?

.net

Solution

If your factory and your classes are in the same assembly you can mark the constructors internal. This will make it so that no classes outside the assembly can call the constructors (without reflection). Your factory, being in the same assembly, sees the constructors as public and, thus, can access them.

Alternatively, you can make the constructors private and use reflection inside your factory to instantiate the objects. You take a small hit using reflection but this doesn't have the assembly restriction and also serves to keep other classes in the same assembly from using anything other than the factory.

Problem

In short I want to prevent objects being instantiated anywhere except in designated static methods in a object factory class. Is this possible?

Original source