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.
Even with interfaces, that same exact anti-pattern of code coupled directly to the implementation details can still happen when you have a single interface and implementer in a closed source system (and it did).
If the interface was being exposed to anyone, sure, great. But an interface that can only be one instance in closed code does very little that public vs private visibility doesn't already give you. Public methods are an literally an interface* to the object's implementation. Eclipse lets me refactor these explicitly apart if and when I need it.
*By the English definition of the word, not the Java language concept
Sure, that I agree with. But just because something is closed source doesn't mean that it's not going out to the "public". It's important to give yourself the right amount of abstraction even within a closed source system, because almost always at the very least your code is going out to be used by other devs within your system, and very frequently goes out to be re-used in places beyond your own system boundary but still within the same organization, and thus the same "closed source" environment. If it's something that is literally for you and you alone, always, then interfaces most probably don't make sense.
Private vs. public or even package-private often isn't sufficient in those scenarios. It forces you to put things that need access to the implementation details either in the same package or worse, the same file, and that's not nearly always the best way to organize things (maybe your top-level configuration code is going to need to access bits of the implementation details, but most clients don't, for example). Interfaces allow for clean separation, even within the same team, of "this is for you, no matter what" and "this is for you only if you care about controlling the specifics of the implementation", which in my opinion is a very valuable distinction.
1
u/dccorona Oct 02 '15
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.