Bird
Raised Fist0

Identify the subtle bug in the following Abstract Factory code snippet that creates Victorian furniture:

medium๐Ÿž Bug Identification Q7 of Q15
OOP & Design Patterns - Factory vs Abstract Factory vs Builder - When to Use Each
Identify the subtle bug in the following Abstract Factory code snippet that creates Victorian furniture:
AVictorianChair class missing lie_on() method
Bcreate_sofa() returns VictorianChair instead of VictorianSofa
CVictorianSofa class missing sit_on() method
DFactory class missing abstract base class inheritance
Step-by-Step Solution
Solution:
  1. Step 1: Inspect create_sofa() method

    It incorrectly returns VictorianChair instance instead of VictorianSofa.
  2. Step 2: Trace method calls

    sofa.lie_on() will fail because VictorianChair lacks lie_on() method.
  3. Final Answer:

    Option B โ†’ Option B
  4. Quick Check:

    Incorrect product returned breaks Abstract Factory contract [OK]
Quick Trick: Factory must return correct product types [OK]
Common Mistakes:
MISTAKES
  • Overlooking wrong return type
  • Assuming missing methods cause bug
Trap Explanation:
PITFALL
  • Candidates confuse missing methods with wrong returned object type.
Interviewer Note:
CONTEXT
  • Tests bug spotting in Abstract Factory implementation.
Master "Factory vs Abstract Factory vs Builder - When to Use Each" 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