According to Factory Method pattern, we delegate object creation to a separate class. Let's say I have abstract class A and some implementors. Implementation is loaded from configuration file with reflection and thus we still operate with type A. I wonder if there is anything wrong with creating static creation method in abstract class. Any comments? The benefit of it is that no additional class is needed. You could argue that besides main functionality it also has the responsibility of creating subtyped objects - would that really violate S principle from SOLID?
public abstract class A
{
// Some abstract stuff
public static A CreateInstance()
{
Type type = GetTypeFromConfig(); // pseudo method
return (A)Activator.CreateInstance(type);
}
}