I am working on a module that requires a strictly decoupled interface. In particular, after creating an instance of the root object (data source), the user should interact only with the object model through interfaces. I have actual factory objects (I call them suppliers) to supply instances that implement these interfaces, but this left a clumsy clue in getting providers. For this, I provided a couple of methods for the data source:
public class MyDataSource { private Dictionary<Type, Type> providerInterfaceMapping = new Dictionary<Type, Type>() { { typeof(IFooProvider), typeof(FooProvider) }, { typeof(IBarProvider), typeof(BarProvider) },
I simplified some details on the fly to simplify (for example, this piece of code does not include the parameters passed to the implementation instance that I created). Is this a good general approach for implementing a factory method in C #?
source share