What is a common code smell that signals an interface is violating the Interface Segregation Principle?
The clearest warning sign is a method implementation whose entire body is throwing UnsupportedOperationException, returning null unexpectedly, or doing nothing at all — a class technically satisfies the interface's compile-time contract but genuinely can't provide the behavior. Another sign is a large interface where different implementers each leave a different subset of methods unimplemented or stubbed, which suggests the interface is really several unrelated capabilities bundled together rather than one coherent contract. A third sign is defensive calling code — try/catch blocks wrapped around interface method calls specifically because some implementations are known to not really support them — which shows the interface's promise can't actually be trusted at the type level. The fix in every case is the same: split the interface along the capabilities that genuinely vary between implementers, so each implementer only commits to what it can honestly deliver.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response