CHAPTER 6

image

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.