I have an object, an in-memory data provider, which contains a lot of data. The dilemma I'm facing is how to get other objects to use this data without passing them the data provider. I would like to keep objects and their methods, that use this data, as decoupled from the data provider as possible. But I'm also not able to extract the needed data and pass it to objects. I was thinking of creating some helper classes with very restricted functionality, wrap the data provider inside, and pass them around. It this a good idea or does anyone know better? Refactoring the methods, so the needed data can be extracted from the data provider, before passing it to the methods is actually an option, but it would require a lot of work.
Asked
Active
Viewed 62 times
0
-
1Why do you think *"passing them the data provider"* counts as coupling? You can then easily swap out to a different data provider in the future, as long as it retains the same API/signature (or can be wrapped in something that does). Could you give a more concrete example of the issue? – jonrsharpe Nov 04 '15 at 16:37
-
Sounds to me like all you need are multiple interface classes to a data provider, which isn't a lot of work, nor would it necessarily require the all the allowed data to be extracted first. – martineau Nov 04 '15 at 16:46
-
Well, because the data provider would become a singleton and I'm not really sure if thats a good idea. But according to a comment in this thread some people think singletons are perfect for caching data, which is what my data provider actually is: http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons – kafka Nov 04 '15 at 16:50