Test-Only Interfaces
You can mitigate the exposure of changing access levels. You can introduce test-only interfaces to combine access level change with a weaker form of breaking down your class. In general, it enhances extensibility and testability to use interfaces as the primary types rather than concrete classes. From an object-oriented design perspective, this separates your definition of the behavioral specification from its implementation. Also, Java’s mocking frameworks work best with interfaces, although they are getting better at handling concrete classes.
By using interfaces as the primary types, callers can only access the methods defined in that interface unless they have the bad manners to use the implementation class directly. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access