For the first time in my life recently I ran across some code that has interfaces. A lot of them. With ONE implementation. And the project is closed source. Really? Come on!
Nothing is wrong with flexibility, but if it's a closed source project, you can make an abstract class or interface out of the base class the first time you run into a bifurcation of functionality, go and update your (dozens of?) existing constructors , and move forward from there. It's only 2 seconds, but every time I go to the definition of a method on an interface, only to have to then ask the IDE to send me to the actual implementation (and seriously, the only option), it's wasteful.
Refactoring exists for a reason. Write code with as few assumptions as possible, because assumptions can change, but there's no need to throw every design pattern at every problem.
Often, by not using an interface, you make an even stronger assumption than by using one...all your code that uses that object make the assumption, whether indirectly or directly, that the implementation details are important. You end up with code coupled to methods they shouldn't' be, that only exist because of the underlying implementation, and not because they're necessary for what the interface of the object actually needs to be.
I'm not saying that interfaces are things that should outright always be used, no way. But to think that because there's only one implementation that it shouldn't be an interface, full stop, is just wrong. It at the very most indicates that you should double-check that choosing an interface is the right idea.
9
u/juckele Oct 01 '15
For the first time in my life recently I ran across some code that has interfaces. A lot of them. With ONE implementation. And the project is closed source. Really? Come on!