Card 04/ 08

ConceptDifficulty: Intermediate1 min

Declare the Interface, Create the Implementation

A method that used to take an ArrayList needs to accept a list built somewhere else, and the somewhere else produces a LinkedList. The change is one word, in eleven files.

java
List<String> refs = new ArrayList<>();

void report(List<String> refs) { }
the interface on the left and in the parameter; the class only after new

The declared type is a statement about what you need. List says "something ordered that I can walk", which is true of every list ever written. ArrayList says "this exact class", which is more than you needed and less than you can get.

What each declaration commits you to
Declared asAcceptsChanging the implementation
List<String>Any listOne word, in one place
ArrayList<String>Only ArrayList and its subclassesEvery declaration and every signature

This matters most at method boundaries. A parameter typed ArrayList refuses List.of(...), refuses Arrays.asList(...), and refuses whatever a library hands you — none of which is a decision anyone made on purpose.

So name the interface everywhere except immediately after new. It costs nothing, and it is what lets the choice of implementation stay a local decision rather than a signature everybody has to agree with.