Bird
Raised Fist0
LLDsystem_design~5 mins

Interface Segregation Principle in LLD - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is the Interface Segregation Principle (ISP)?
ISP means that no client should be forced to depend on methods it does not use. It encourages creating small, specific interfaces rather than large, general ones.
Click to reveal answer
beginner
Why is it bad to have fat interfaces?
Fat interfaces make clients depend on methods they don't need, leading to unnecessary complexity and harder maintenance.
Click to reveal answer
beginner
Give a real-life example of the Interface Segregation Principle.
Think of a remote control with many buttons. If you only want to change channels, you shouldn't have to learn how to use the volume or settings buttons. Separate remotes for different functions follow ISP.
Click to reveal answer
intermediate
How does ISP improve system design?
ISP improves flexibility, reduces side effects from changes, and makes code easier to understand and test by keeping interfaces focused.
Click to reveal answer
intermediate
What is a common sign that an interface violates ISP?
When a class implementing the interface has to leave some methods empty or throw errors because they are not relevant to it.
Click to reveal answer
What does the Interface Segregation Principle recommend?
AUse many small, specific interfaces
BUse one large interface for all clients
CAvoid interfaces altogether
DCombine unrelated methods in one interface
Which problem indicates a violation of ISP?
AClients implement methods they never use
BInterfaces have too few methods
CClasses have too many dependencies
DMethods have too many parameters
How does ISP affect code maintenance?
AMakes it harder by adding more interfaces
BMakes it easier by reducing unnecessary dependencies
CHas no effect on maintenance
DRequires rewriting all classes often
Which analogy best explains ISP?
AA Swiss Army knife with many tools
BA single key for all locks
CA toolbox with all tools mixed
DA TV remote with only volume buttons for volume control
What is a benefit of following ISP?
AInterfaces become very large
BAll clients share the same interface
CClients depend only on methods they use
DClasses implement many unrelated methods
Explain the Interface Segregation Principle and why it matters in system design.
Think about how forcing clients to use unused methods can cause trouble.
You got /4 concepts.
    Describe a real-world example that illustrates the Interface Segregation Principle.
    Consider everyday tools or devices with specialized controls.
    You got /3 concepts.

      Practice

      (1/5)
      1. What is the main idea behind the Interface Segregation Principle in system design?
      easy
      A. Interfaces should be as large as possible to cover all features.
      B. All classes must implement every method of an interface.
      C. Clients should only depend on methods they actually use.
      D. Interfaces should be avoided to reduce complexity.

      Solution

      1. Step 1: Understand the principle's goal

        The Interface Segregation Principle aims to keep interfaces small and focused so clients are not forced to depend on unused methods.
      2. Step 2: Match the correct description

        Clients should only depend on methods they actually use. correctly states that clients should only depend on methods they use, which aligns with the principle.
      3. Final Answer:

        Clients should only depend on methods they actually use. -> Option C
      4. Quick Check:

        Interface Segregation Principle = Clients depend only on used methods [OK]
      Hint: Focus on clients using only needed methods [OK]
      Common Mistakes:
      • Thinking interfaces must be large and cover all features
      • Believing all classes must implement every interface method
      • Assuming interfaces should be avoided
      2. Which of the following interface definitions follows the Interface Segregation Principle?
      easy
      A. interface Printer { void print(); void scan(); void fax(); }
      B. interface Machine { void doEverything(); }
      C. interface Device { void operate(); void print(); void scan(); void fax(); }
      D. interface Printer { void print(); } interface Scanner { void scan(); }

      Solution

      1. Step 1: Analyze interface sizes

        interface Printer { void print(); } interface Scanner { void scan(); } splits responsibilities into separate interfaces for printing and scanning, keeping them focused and small.
      2. Step 2: Compare with other options

        Options A, B, and C combine multiple unrelated methods into one interface, violating the principle.
      3. Final Answer:

        Separate interfaces for each responsibility -> Option D
      4. Quick Check:

        Small focused interfaces = interface Printer { void print(); } interface Scanner { void scan(); } [OK]
      Hint: Look for interfaces with single focused responsibility [OK]
      Common Mistakes:
      • Choosing interfaces with many unrelated methods
      • Ignoring separation of concerns
      • Confusing interface segregation with inheritance
      3. Given these interfaces and classes, what will be the output?
      interface Printer { void print(); }
      interface Scanner { void scan(); }
      class MultiFunctionDevice implements Printer, Scanner {
        public void print() { System.out.println("Printing document"); }
        public void scan() { System.out.println("Scanning document"); }
      }
      
      MultiFunctionDevice device = new MultiFunctionDevice();
      device.print();
      device.scan();
      medium
      A. Printing document\nScanning document
      B. Printing document
      C. Scanning document
      D. Compilation error

      Solution

      1. Step 1: Understand class implementation

        The class implements both Printer and Scanner interfaces and provides both methods.
      2. Step 2: Trace method calls

        Calling device.print() prints "Printing document" and device.scan() prints "Scanning document".
      3. Final Answer:

        Printing document\nScanning document -> Option A
      4. Quick Check:

        Both methods print messages = Printing document\nScanning document [OK]
      Hint: Check which interfaces are implemented and methods called [OK]
      Common Mistakes:
      • Assuming only one method runs
      • Expecting compilation error due to multiple interfaces
      • Confusing method outputs
      4. Identify the problem in this interface design violating the Interface Segregation Principle:
      interface Worker {
        void work();
        void eat();
      }
      
      class Robot implements Worker {
        public void work() { System.out.println("Robot working"); }
        public void eat() { throw new UnsupportedOperationException(); }
      }
      medium
      A. Worker interface is too broad, forcing Robot to implement unused methods.
      B. Robot should implement eat() properly.
      C. Robot class should not implement Worker interface.
      D. No problem, this design is correct.

      Solution

      1. Step 1: Analyze interface methods

        The Worker interface combines work and eat methods, but Robot cannot eat.
      2. Step 2: Identify violation

        Robot is forced to implement eat() which it does not support, violating Interface Segregation Principle.
      3. Final Answer:

        Worker interface is too broad, forcing Robot to implement unused methods. -> Option A
      4. Quick Check:

        Broad interface forcing unused methods = Worker interface is too broad, forcing Robot to implement unused methods. [OK]
      Hint: Check if all interface methods apply to all implementers [OK]
      Common Mistakes:
      • Thinking Robot must implement eat() properly
      • Believing no problem exists
      • Suggesting Robot should avoid interface
      5. You are designing a payment system with interfaces for different payment methods. Which design best follows the Interface Segregation Principle?
      hard
      A. interface Payment { void payWithCard(); void payWithCash(); void payWithCrypto(); }
      B. interface CardPayment { void payWithCard(); } interface CashPayment { void payWithCash(); } interface CryptoPayment { void payWithCrypto(); }
      C. interface Payment { void pay(); } class AllPayments implements Payment { void pay() { /* all methods */ } }
      D. interface Payment { void payWithCard(); void payWithCash(); } class CryptoPayment implements Payment { void payWithCard() {} void payWithCash() {} }

      Solution

      1. Step 1: Evaluate interface segregation

        interface CardPayment { void payWithCard(); } interface CashPayment { void payWithCash(); } interface CryptoPayment { void payWithCrypto(); } splits payment methods into separate interfaces, allowing clients to implement only what they need.
      2. Step 2: Compare other options

        Options A, B, and D force clients to implement methods they may not use, violating the principle.
      3. Final Answer:

        Separate interfaces for each payment method -> Option B
      4. Quick Check:

        Separate interfaces = interface CardPayment { void payWithCard(); } interface CashPayment { void payWithCash(); } interface CryptoPayment { void payWithCrypto(); } [OK]
      Hint: Split interfaces by payment method for flexibility [OK]
      Common Mistakes:
      • Combining all payment methods in one interface
      • Forcing classes to implement unused methods
      • Ignoring interface segregation benefits
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard