Code Against Interfaces, Not Implementations

An old and true rule of thumb useful for every piece of code is to “separate your code into interface and implementation and then let other parts of the system rely just on the interfaces.” This advice is much older than Java, but it’s so true that it’s valuable to investigate its implications for writing Java APIs. This chapter provides an overview from various angles.

First, this rule of thumb implies that if you have a working application and want to provide some APIs to allow others to access it, it’s not reasonable simply to make a few classes public and then pretend it is an API. Without ...

Get Practical API Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.