Card 01/ 08

ConceptDifficulty: Intermediate1 min

Naming What a Thing Can Do Without Saying How

A reporting method needs to sort things. It does not care whether they are invoices, employees or files — only that any two of them can be put in an order.

An interface is a name for that capability and nothing else. It lists method signatures with no bodies, and any class can declare that it supplies them.

java
interface Archivable {
    String archiveKey();
    boolean isExpired();
}

A class that writes implements Archivable is promising those two methods exist. The compiler enforces the promise: leave one out and the class will not build.

What an interface declares and what it leaves to the class
The interface decidesThe class decides
Which methods exist, and their signaturesWhat each method does
That anything implementing it can be used interchangeablyWhat state it keeps to do the job

So code written against Archivable works with every class that ever implements it, including ones written after that code shipped. That is the payoff: the calling code names a capability rather than a list of types, and the list of types is free to grow.