3 ms·
I would argue you should inject concrete implementations until you need an interface. Why add unnecessary indirection?
by caseymarquis 7y ago
I would argue you should inject concrete implementations until you need an interface. Why add unnecessary indirection?
- mrkeen 7y agoIt lets you constrain your logic code to depend as loosely as possible on its dependencies. If I start from a concrete 'FooDatabase' (and wait until later to interface it), I might start putting things like open(), close(), flush(), etc. into my logic code. Then when I interface it, it will just be unnecessary indirection. If I start from the other end and think "I just need somewhere to put my Foos", then I'll pass in a Consumer<Foo> and be done with it.