Here's the situation: I've got a class that is doing too much. It's mainly for accessing configuration information, but it also has the database connection. It's implemented as a singleton, so this also makes unit testing it difficult as most code is pretty tightly coupled to it. This is even more problematic as it creates an import-time dependency (we're doing this in Python), which means that certain modules must be imported in a certain order. Ideally, I'd like to both split this into two classes and make it a non-singleton.
Fortunately, my employer has warmed up to the fact that this kind of testing is good and is willing to permit me to make changes like this if it makes code more testable. However, I doubt that they will be willing to allow me to spend too much time on it. And I'd rather fix this incrementally rather than trying to be too radical.
So, I see three choices here:
- Break the configuration object into a (singleton) configuration object and a (non-singleton) database object. This would at least allow me to remove the database as an import-time dependency.
- Make the configuration object a non-singleton and pass it to objects that need it. I feel that this better addresses our short-term needs, but I think it would take significantly more time.
- Do something I hadn't thought of that you suggest in your answer. :-)
So what do I do?