Factory vs instance constructors
- by Neil N
I can't think of any reasons why one is better than the other. Compare these two implementations:
public class MyClass
{
public myClass(string fileName)
{
// some code...
}
}
as opposed to:
public class MyClass
{
private myClass(){}
public static Create(string fileName)
{
// some code...
}
}
There are some places in the .Net framework that use the static method to create instances. At first I was thinking, it registers it's instances to keep track of them, but regular constructors could do the same thing through the use of private static variables.
What is the reasoning behind this style?