Interface Segregation Principle (ISP)
Don't force clients to depend on methods they don't use — small, focused interfaces over large "fat" ones.
Questions in this quiz
10 questions on Interface Segregation Principle (ISP). Work through them here, then start the quiz to answer them and see your score.
1.The Interface Segregation Principle states:
- AAll interfaces must be implemented by every class
- BInterfaces must have exactly one method
- CInterfaces should never extend other interfaces
- DClients should not be forced to depend on interfaces they do not use — prefer many small, focused interfaces over one large "fat" interface
2.This interface violates ISP. What is the problem?
interface Animal { void eat(); void fly(); void swim(); void run(); } class Dog implements Animal { public void eat() { /* eats */ } public void fly() { throw new UnsupportedOperationException(); } public void swim() { /* swims */ } public void run() { /* runs */ } }- ADog is missing a constructor
- BThe Animal interface forces Dog (and all animals) to implement fly() even though most animals can't fly
- CThis design is correct — animals do all these things
- DDog should extend Animal, not implement it
3.What is the problem with a "fat" interface in terms of change propagation?
- AThere is no practical problem — large interfaces are more maintainable
- BFat interfaces improve performance because fewer objects are created
- CAdding any method to the fat interface forces ALL implementing classes to change — even those that don't need the new method
- DFat interfaces compile slower
4.Java's standard library is a good ISP example. Which design demonstrates ISP?
- AString and StringBuilder being separate classes
- BReadable, Closeable, Iterable, Comparable — small focused single-method interfaces composed à la carte
- CCollections being in a separate package from Arrays
- DList and ArrayList being separate types
5.How does ISP relate to the Single Responsibility Principle?
- AISP is a weaker version of SRP
- BISP applies to interfaces what SRP applies to classes — both aim for focused, single-purpose units that change for one reason
- CSRP applies to methods; ISP applies to packages
- DThey are identical — just different names
6.A Worker interface has work(), eat(), and sleep(). A Robot class implements Worker but throws on eat() and sleep(). What is the ISP fix?
- AMake Robot an abstract class
- BRemove eat() and sleep() from all implementations
- CSplit into Workable { void work(); } and HumanNeeds { void eat(); void sleep(); }. Robot implements Workable; Human implements both
- DAdd a isRobot() method that callers check before calling eat() and sleep()
7.What does "client" mean in the context of "clients should not be forced to depend on interfaces they don't use"?
- AThe database client layer
- BThe class that USES (calls) the interface, not the class that implements it
- CEnd users of the application
- DThe network client making HTTP requests
8.Should every interface have exactly one method to fully comply with ISP?
- AYes — one method per interface is the only way to truly follow ISP
- BNo — ISP only applies to interfaces with more than 10 methods
- CNo — an interface can have multiple related methods as long as all clients of the interface typically use all of them
- DYes, but only for public interfaces
9.A PrinterScanner interface has print(), scan(), fax(), and staple(). A simple printer only supports print(). What is the ISP-compliant design?
- AHave SimplePrinter throw NotImplementedException for scan(), fax(), staple()
- BCreate an AbstractPrinterScanner with default no-op implementations
- CRemove fax() and staple() — modern devices don't need them
- DCreate Printable { print(); }, Scannable { scan(); }, Faxable { fax(); }, Stapleable { staple(); } — classes implement only what they support
10.When would you deliberately create a larger interface combining several smaller ones?
- AOnly when using frameworks like Spring that require it
- BNever — large interfaces always violate ISP
- CWhen the codebase is small and cohesion doesn't matter yet
- DWhen there is a well-defined role that always requires ALL of those capabilities together — e.g., a full CRUD interface for admin screens that always need all four operations