Hacker News new | ask | show | jobs
by equark 5455 days ago
The correct way to deal with this is to realize you have a problem? I think the above comment is willing to admit a problem and is asking for a solution. What does TDD have to do with it?

I'm also interested in hearing what is considered the best practice for things like passing around config options, an eventloop, or message bus.

1 comments

The solution is essentially to take a hard look at your design and see why you have to pass around config options, event loops, or message buses to begin with. The need to access global state is a code smell.

When you DO need global state, then a singleton object is a reasonable way to achieve it. But chances are fairly high that you don't.

You can look for days, and if you don't know any of the alternatives, none will pop out.

As I'm not in the mobile sphere, I wouldn't know how to avoid a singleton for an app that is constrained by speed and space requirements. I've already shown an example above, what's your solution in this environment, with the constraints of the questioner?