Is it possible to separate interface from implementation where the client assembly has no idea of the actual implementation and works only on the interfaces. If we offload the object creation to another component, it will still create a dependency on the actual implementation types.
I can think of doing this using reflection where a layer is responsible for serving the objects which are cast as interfaces. The actual instantiation of the types are done through reflection and stored in a dictionary where the key is the interface and value the implementation object. This way the client code has no idea of the type of implemenation.
Is there a design pattern to do this without reflection?
Thanks in advance for the answers
Reflection is useful in scenario of dynamic allocation, for example in case of plugin-based systems. If you don’t want to manage that kind of environment, just declare all implementaions in the code and use only interface in consumer.
The thing is, that in both cases, in some point there have to be “someone” who decides which real type to create. In case of plugin-based logic it could be, say,
PluginManager, in other case would be somefactorymethod/calss.Design pattern is IoC, if you’re ineterested in.
Hope this helps