3 ms·
> Another example is the Config object. When I started the Python code back in 2005, I was very excited about using the idea of dependency injection for connect
by mercurial 13y ago
> Another example is the Config object. When I started the Python code back in 2005, I was very excited about using the idea of dependency injection for connecting together software modules (this is the basis of how 0install runs programs). Yet, for some reason I can’t explain, it didn’t occur to me to use a dependency injection style within the code. Instead, I made a load of singleton objects. Later, in an attempt to make things more testable, I moved all the singletons to a Config object and passed that around everywhere. I wasn’t proud of this design even at the time, but it was the simplest way forward.
That's called a "god object", unless I'm mistaken. It's an abomination in any language. I have the misfortune of maintaining a codebase with this "feature". Never, ever, do anything like this.
- raphinou 13y agoNever used or inherited such a design, but I'm curious about what practical problem you encoutered. Care to illustrate?
- mercurial 13y agoOnce you have implemented this design pervasively, you can forget about reusing your code in another context. Because it is impossible to tell which part of the god object is needed in a given part of the code, you have to initialize everything in the god object. With a bit of luck, you're working in Java and mixing this anti-pattern with some Spring dependency injection, in order to make this mess really impossible to untangle. And obviously it encourages mixing up layers. Why have modularity when you can access your data access components from anywhere? And in general, circular dependencies are a code smell. Whenever I thought I needed to use them, I came to realize it was the wrong decision.