Possible Duplicate:
Factory pattern in C#: How to ensure an object instance can only be created by a factory class?
Suppose I have a Factory class that knows how to make a Square. If I feel that only the Factory class knows how to make a square and I want to prevent others (even in the same assembly) from creating a Square what would be the correct (if there is such a thing) way to go about it?
You could move the factory and the class to an assembly and mark the class’s constructor as internal so that it can only be called from within the assembly.
Note that this would allow other assembly members to access the constructor though, not only the factory.
This is how the
Lookup<TKey, TElement>works for instance.