CSE Roadmap

Common tier · about 2 hours · 6 parts

Part 5 of 6 · 2 min read

Beyond Java

The same trouble at larger scale.

It is not only about Java

CA points out that in a dynamically typed language such as Python or Ruby, source files do not import declarations, so the recompilation problem does not exist. This could suggest that ISP is a language matter. CA argues that it is not.

The deeper concern is that depending on something that carries more than you need is harmful. CA gives an example: a system S adopts a framework F, and F was built around one specific database D. The chain is S needs F, and F needs D. Suppose D has features that F never touches. A change in those features can still force F to be released again, and then S as well. A fault in D can also spread up the chain.

The lesson is general: leaning on something that carries extras you never use can bring trouble you did not plan for. In everyday work this means preferring a small library to a giant one when you need one function, and asking a service for a narrow API instead of its whole data model.

In an interview, ISP shows up whenever you draw an interface. Ask for each caller: "which of these methods does it use?". If a caller uses two of eight, split.

Interview angle

Answer in your head first, then open it.

What is ISP?

Callers should depend only on the methods they use, so big interfaces are split by purpose.

What problem does it solve?

A change to a method that a caller never uses should not force that caller to change or be released again.

Does it matter outside Java?

Yes. Depending on a framework or database with unused features still ties you to its failures and changes.

Check yourself: 1. Why does the recompilation problem not exist in Python? 2. What does the framework and database example show?

Words you will meet

Word Meaning
Fat interface An interface with many methods that callers use only in part
Segregation Separating into smaller parts by purpose
Dependency Something one piece of code needs in order to work
Baggage Extra features carried along that a caller does not need
Recompile Build code again after something it depends on changed