Bird
Raised Fist0

Identify the bug in the following Builder pattern code snippet that constructs a luxury house:

medium🐞 Bug Identification Q14 of Q15
OOP & Design Patterns - Factory vs Abstract Factory vs Builder - When to Use Each
Identify the bug in the following Builder pattern code snippet that constructs a luxury house:
Aget_result method returns the wrong object
BConstructor does not initialize the House object
CDirector does not call build_roof method
DLine with 'pass' in build_pool method lacks adding 'Pool' part
Step-by-Step Solution
  1. Step 1: Inspect build_pool method

    The build_pool method contains only 'pass', so it does not add the 'Pool' part to the house.
  2. Step 2: Check Director.construct_luxury_house calls

    The Director calls build_pool expecting the pool to be added, but due to missing implementation, it is not.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Missing pool addition causes incomplete luxury house [OK]
Quick Trick: Empty build_pool method -> missing part added [OK]
Common Mistakes:
MISTAKES
  • Confusing constructor initialization
  • Ignoring missing method implementation
Trap Explanation:
PITFALL
  • Other lines look suspicious but are correct; missing implementation is subtle and common.
Interviewer Note:
CONTEXT
  • Tests ability to spot subtle bugs in Builder pattern implementations.
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