Bird
Raised Fist0

Considering maintainability, what is a key disadvantage of using abstract classes instead of interfaces in evolving APIs?

medium🪤 Complexity Trap Q6 of Q15
OOP & Design Patterns - Abstraction - Abstract Class vs Interface - When to Use Which
Considering maintainability, what is a key disadvantage of using abstract classes instead of interfaces in evolving APIs?
AAbstract classes cannot provide default implementations, limiting maintainability.
BInterfaces allow adding new methods without breaking existing implementations; abstract classes do not.
CAbstract classes force all subclasses to recompile when changed, while interfaces do not.
DInterfaces cannot be extended, making them less maintainable than abstract classes.
Step-by-Step Solution
Solution:
  1. Step 1: Understand API evolution constraints

    Adding methods to interfaces traditionally breaks existing implementations unless default methods are used.
  2. Step 2: Compare abstract classes and interfaces

    Abstract classes can add new concrete methods without breaking subclasses; interfaces historically could not, but modern languages allow default methods.
  3. Step 3: Identify key disadvantage

    Abstract classes force recompilation of subclasses when changed; interfaces with default methods allow adding methods more safely.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Abstract classes require recompilation of subclasses; interfaces with default methods ease API evolution [OK]
Quick Trick: Abstract classes require subclass recompilation on change [OK]
Common Mistakes:
MISTAKES
  • Assuming abstract classes never break subclasses
  • Believing interfaces cannot have default methods
  • Confusing recompilation requirements
Trap Explanation:
PITFALL
  • Candidates overlook recompilation needs of abstract classes and default methods in interfaces.
Interviewer Note:
CONTEXT
  • Evaluates understanding of maintainability trade-offs in abstraction choices.
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