Your interface has twelve methods and most implementers leave several empty. How do you fix it without breaking everything?
Introduce smaller role interfaces, make the big interface extend them, move clients to the small ones gradually, then retire the old one. Existing code keeps compiling throughout.
Explain it simply
Renovating a shop without closing it: first build the new counters, then move customers over one by one, and only then remove the old counter. A sudden removal would break every caller at once.
Example
// Step 1: extract roles
interface Readable { String read(String id); }
interface Writable { void write(String id, String data); }
interface Deletable { void delete(String id); }
// Step 2: old interface keeps working, now built from the roles
interface Storage extends Readable, Writable, Deletable { }
// Step 3: clients ask for what they need
class Report {
String build(Readable source) { return source.read("sales"); }
}
// Step 4: new implementers pick roles
class ArchiveStore implements Readable { public String read(String id) { return "..."; } }Old implementers of Storage still compile. Over time, callers switch to the narrow roles, and Storage can be removed once nothing uses it.
What to say in the interview
"I extract role interfaces, have the old interface extend them for compatibility, migrate callers to the narrow ones, and delete the old one at the end. This avoids a big-bang change while giving new classes small contracts."
Common mistakes
- Deleting the big interface in one commit and fixing the build afterwards.