Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interface Best Practice

Probably a general question, but it is considered a bad practice to have an interface (Service), and an implementation of it (ServiceImpl), but with ServiceImpl containing private utility methods that are not contained in the interface?

like image 633
EdgeCase Avatar asked Dec 06 '25 08:12

EdgeCase


2 Answers

Not bad practice at all - I'd expect almost any non-trivial concrete implementation class to contain private methods. The alternative would often be to have much too large method bodies within the class.

Don't forget, no-one outside the class should care at all whether you've got lots of private methods or not. They should only care about your public API (or your package / protected API where relevant).

like image 193
Jon Skeet Avatar answered Dec 08 '25 21:12

Jon Skeet


No not at all, exactly what you should do.

like image 38
Mattias Isegran Bergander Avatar answered Dec 08 '25 22:12

Mattias Isegran Bergander