Hacker News new | ask | show | jobs
by kilemensi 4565 days ago
What you're talking about is decoupling interface from implementation. This is good (well, it's good if there is a genuine need for more than one implementation, otherwise it's just decoupling for the sake of decoupling which is a form of waste. Remember YAGNI)

My understanding of reuse is when the same peace of code is used in different areas of the project. This could be different classes, different packages, different modules, etc. Now the more the code is reused, the more tight coupling between the two pieces of code i.e. change to the interface of the reused code 'could' mean change(s) to each and every place the reused code is being called.

Secondly, if you put reuse high up in the design requirement, what you sometimes end up with are very generic interfaces/classes that can be reused in lots of places as opposed to very specific interfaces/classes or unnecessary inheritence trees required to change the base class behaviour in those places where the required behaviour is 'slightly different'.

Lastly, not so long ago, DI containers did not support package private visibility. This means all injection (constructor, setter, etc.) required public visibility. This lead to a lot of developers also 'reusing' code even in places where they shouldn't just because they could i.e. it's right there!