2 ms·
> the senior engineer had defined every single service class as an interface and then implemented that interface in an actual @Service. The logic from the seni
by gedy 5y ago
> the senior engineer had defined every single service class as an interface and then implemented that interface in an actual @Service. The logic from the senior engineer was that the interface represented the “contract” and the class the business logic.
This is mentioned as bad thing, but having service interfaces really helped in a large Java project I worked, where we had to reimplement and extract some important code. Using the interface for the new code made it much simpler to use a radically different implementation, and also made devs think about what the real interface should be, vs just coupling to some implementation.
- KronisLV 5y agoThere is a large difference between dogmatically declaring that every single service needs an interface, versus just introducing them at the point where you actually need more than one implementation. I think that's the author's original argument - not that interfaces are bad in of themselves, but that cargo culting is problematic. Furthermore, starting with an interface oftentimes makes you create the wrong abstraction, however when you have a concrete implementation, in my experience extracting an interface becomes easier to do, though mostly thanks to excellent IDE tooling.
- floverfelt 5y agoExactly, it would've made total sense to pull it out into an interface in other situations, but simply felt like a preference here.