February 4, 2016 Dependency Inversion Principle (DIP)
I often hear this: Why should we extract this code? We only use it in one place. It doesn’t make sense to extract it. And yet, that same person wants to write tests for private
(or otherwise invisible) behavior. That person is only hurting themselves: they want to treat this code like a separate thing (because they want to test it), but they resist extracting it because “it doesn’t feel right”. I have safely extracted numerous mini-frameworks and mini-libraries and my only regret remains that I couldn’t easily have used someone else’s library for this in the first place. (How many times to we need to reimplement processing command line arguments? Mapping data from Java to SQL? Processing HTTP request headers? Hasn’t someone solved these already?)
This is a companion discussion topic for the original entry at https://blog.thecodewhisperer.com/permalink/how-reuse-happens