Bird
Raised Fist0

Consider the Builder pattern code where the Director constructs a house with no parts (empty build). What will print(house) output after this construction?

medium🧾 Code Trace Q4 of Q15
OOP & Design Patterns - Factory vs Abstract Factory vs Builder - When to Use Each
Consider the Builder pattern code where the Director constructs a house with no parts (empty build). What will print(house) output after this construction?
AHouse parts: Walls, Roof
BHouse parts: None
CHouse parts:
DHouse parts: Pool
Step-by-Step Solution
Solution:
  1. Step 1: Director.construct_empty_house() does nothing

    No parts are added to house.parts list.
  2. Step 2: __str__ method returns string

    Since parts list is empty, the conditional returns "House parts: None".
  3. Final Answer:

    Option B → Option B
  4. Quick Check:

    Empty parts list leads to 'House parts: None' output [OK]
Quick Trick: Empty parts list returns 'House parts: None' due to conditional [OK]
Common Mistakes:
MISTAKES
  • Assuming empty join returns empty string output
  • Expecting default parts added
Trap Explanation:
PITFALL
  • Candidates confuse empty list join with explicit 'None' string due to conditional.
Interviewer Note:
CONTEXT
  • Tests edge case handling and string representation in Builder pattern.
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