The whole point of the Factory Pattern is that only Factory knows how to select and create an object, and it provides only object objects, instance objects through an interface, not a specific class. The closure of the private object constructor is due to the fact that Factory itself cannot create it.
Decision:
1- Define an interface class that implements all types of Extrude20XX classes, such as IExtrudeStuff .
2- Wrap Extrude20XX classes inside the Factory class as private nested classes.
3- Implement the IExtrude interface in all ExtrudeXX classes.
4- Write the (static) Create (t) method, for example:
public static class ExtrudeFactory { public static IExtrudeStuff Create(ExtrudeType t) { { switch (t) { case ExtrudeType.Extrude2013: return new Extrude2013 (); case ExtrudeType.Extrude2014: return new Extrude2014 (); default: return null; } } }
source share