Bird
Raised Fist0

When applying the Open/Closed Principle, what is a potential downside related to performance?

medium🪤 Complexity Trap Q6 of Q15
OOP & Design Patterns - Open/Closed Principle - Open for Extension, Closed for Modification
When applying the Open/Closed Principle, what is a potential downside related to performance?
APolymorphic calls can introduce slight runtime overhead compared to direct calls.
BInlining of methods is always guaranteed, improving performance.
CUsing interfaces eliminates all runtime overhead.
DExtending classes reduces memory usage significantly.
Step-by-Step Solution
Solution:
  1. Step 1: Understand performance implications of OCP

    OCP often uses polymorphism, which can add runtime overhead due to dynamic dispatch.
  2. Step 2: Analyze options

    Polymorphic calls can introduce slight runtime overhead compared to direct calls correctly states polymorphic calls add slight overhead. Inlining of methods is always guaranteed, improving performance is false; inlining is not always guaranteed with polymorphism. Using interfaces eliminates all runtime overhead is false; interfaces add some overhead. Extending classes reduces memory usage significantly is false; extending classes usually increases memory usage.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Polymorphism adds runtime dispatch overhead [OK]
Quick Trick: Polymorphism adds runtime overhead due to dynamic dispatch [OK]
Common Mistakes:
MISTAKES
  • Assuming interfaces eliminate overhead
  • Believing method inlining always occurs
Trap Explanation:
PITFALL
  • Candidates underestimate runtime cost of polymorphism, assuming zero overhead.
Interviewer Note:
CONTEXT
  • Tests awareness of performance trade-offs in OOP design.
Master "Open/Closed Principle - Open for Extension, Closed for Modification" 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