Re:Building an interface (even if there's only one implement...
by marginalia_nu on Wednesday May 25, 2022 @10:28PM
(#31513573)
I think the purpose of (Java) interfaces should be primarily seen as a means to decouple code that shouldn't be tightly coupled, rather than a means to offer polymorphism. It's relatively rare that multiple implementations of the same interface is desirable, it definitely happens, but not too much.
It's a bit of a balance. Decoupling can definitely be taken too far. Anyone who has worked in the language has no doubt encountered the ravioli code left by someone who has just read Clean Code and has fully embraced Uncle Bob as their lord and savior.
In the end the need for this interface-as-decoupling pattern has dropped significantly with modern dependency injection and ad-hoc mocking libraries like Mockito. They grant most the benefits of these single-child interfaces with virtually none of the drawbacks.
It's a bit of a balance. Decoupling can definitely be taken too far. Anyone who has worked in the language has no doubt encountered the ravioli code left by someone who has just read Clean Code and has fully embraced Uncle Bob as their lord and savior.
In the end the need for this interface-as-decoupling pattern has dropped significantly with modern dependency injection and ad-hoc mocking libraries like Mockito. They grant most the benefits of these single-child interfaces with virtually none of the drawbacks.