Bird
Raised Fist0

In a scenario where several unrelated classes must implement the same set of method signatures but share no implementation, which abstraction technique should be used?

easy💻 Programming Q1 of Q15
OOP & Design Patterns - Abstraction - Abstract Class vs Interface - When to Use Which
In a scenario where several unrelated classes must implement the same set of method signatures but share no implementation, which abstraction technique should be used?
AUse a concrete class and inherit from it.
BUse an abstract class with implemented methods.
CUse an interface to define the method signatures.
DUse a singleton pattern to enforce method implementation.
Step-by-Step Solution
Solution:
  1. Step 1: Identify requirement

    Multiple unrelated classes must implement certain methods without sharing code.
  2. Step 2: Choose abstraction

    Interfaces define method signatures without implementation, perfect for unrelated classes.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Interfaces enforce contracts without code sharing [OK]
Quick Trick: Interfaces enforce method contracts without code sharing [OK]
Common Mistakes:
MISTAKES
  • Choosing abstract class which forces code sharing
  • Using concrete class inheritance which limits unrelated classes
  • Singleton pattern unrelated to enforcing method contracts
Trap Explanation:
PITFALL
  • Abstract classes imply shared code, which is not required here.
Interviewer Note:
CONTEXT
  • Tests understanding of when to use interfaces for unrelated classes.
Master "Abstraction - Abstract Class vs Interface - When to Use Which" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes