Bird
Raised Fist0

If you want to reuse parts already built in a complex object (e.g., reuse walls and roof when building multiple houses), which modification to the Builder pattern is most appropriate?

hard🎤 Interviewer Follow-up Q15 of Q15
OOP & Design Patterns - Factory vs Abstract Factory vs Builder - When to Use Each
If you want to reuse parts already built in a complex object (e.g., reuse walls and roof when building multiple houses), which modification to the Builder pattern is most appropriate?
AModify the Builder to reset the product after each get_result call to avoid reuse.
BUse Abstract Factory instead, as it naturally supports part reuse.
CCache built parts inside the Builder and reuse them when building new objects.
DSwitch to Factory pattern for simpler object creation and reuse.
Step-by-Step Solution
  1. Step 1: Understand reuse requirement

    Reusing parts means the Builder should keep built parts cached and reuse them instead of rebuilding.
  2. Step 2: Evaluate options

    Cache built parts inside the Builder and reuse them when building new objects. caches parts inside Builder, enabling reuse. Modify the Builder to reset the product after each get_result call to avoid reuse. resets product, preventing reuse. Abstract Factory and Factory do not handle stepwise reuse well.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Caching parts in Builder enables reuse efficiently [OK]
Quick Trick: Cache parts in Builder to enable reuse [OK]
Common Mistakes:
MISTAKES
  • Resetting product disables reuse
  • Confusing Abstract Factory with Builder reuse
Trap Explanation:
PITFALL
  • Resetting product looks safe but breaks reuse; Abstract Factory does not handle stepwise reuse.
Interviewer Note:
CONTEXT
  • Tests candidate's depth in adapting Builder pattern for reuse scenarios.
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