At the moment, I'm learning a little bit about oop/ood and try to refactor some old unmaintainable android application. It's basically a WebView which is providing all kinds of device features via a Javascript API. So the API is one big class, which was added via addJavascriptInterface. Inside of that class different objects will be created (TTS, barcodescanner, speechrecon., sensors etc.) via singletons.
I could create those objects outside and pass it via DI but at the end that constructor would have like 20 objects inside of it and I would have to create those objects even if I don't need them. A better solution might be to pass factories and create the objects inside of the JavascriptInterface-class, but that still wouldn't change the fact that I have like 20 different responsibilities inside that class.
Is there any nice and clean way to solve that problem and avoid tight coupling and singletons or is that even a situation where a singleton is a good choice?
Aucun commentaire:
Enregistrer un commentaire