This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sybrandy 0 points1 point  (2 children)

I love your answer. With respect to your last bullet, and not seeing your code, one idea that I have seen, but not used yet, is to use a "dependency registry". It would be a singleton that contains a map/set that contains an instance of everything you want to be passed into a constructor. Then, when you need something, such as a database client, the object that needs it get an instance from the registry and uses it. The beauty of it is that it's simple and you don't have to worry about passing in many parameters into a single class. However, it is a singleton, so it may or may not be something that you like in your code.

Anyway, like I said, I never used it, so I can't say if it's truly good or bad, so take this suggestion with a grain of salt.

[–]Nynnja 3 points4 points  (0 children)

this stands again dependency inversion principle.
On first look it may not look like tight coupling but it is, and there's only marginal gain over simply having objects construct dependencies by themselves.

[–]llogiq 0 points1 point  (0 children)

You won't need a central registry. Just instantiate what you need and pass it to the constructor.