Re:Goodbye, shitty Car extends Vehicle object-orientation tu...
by twblalock on Saturday October 19, 2019 @02:24PM
(#21299923)
These days I find composition via dependency injection (of interfaces, not concrete implementations) to be a much better way to solve #3.
[ Parent
| on HN ]
Re:Goodbye, shitty Car extends Vehicle object-orientation tu...
by caseymarquis on Saturday October 19, 2019 @03:57PM
(#21300429)
I would argue you should inject concrete implementations until you need an interface. Why add unnecessary indirection?
Re:Goodbye, shitty Car extends Vehicle object-orientation tu...
by mrkeen on Saturday October 19, 2019 @05:48PM
(#21300974)
It 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.