Bird
Raised Fist0

Given the following partial output from a beverage preparation using the Template Method Pattern: Boil water Steep tea bag Pour into cup Which of the following is the most likely original input or subclass used?

hard🔄 Reverse Engineer Q9 of Q15
OOP & Design Patterns - Template Method Pattern - Define Skeleton, Override Steps
Given the following partial output from a beverage preparation using the Template Method Pattern: Boil water Steep tea bag Pour into cup Which of the following is the most likely original input or subclass used?
ATea subclass with condiments skipped via hook method
BCoffee subclass with condiments skipped
CTea subclass with condiments added
DCoffee subclass with condiments added
Step-by-Step Solution
Solution:
  1. Step 1: Analyze output steps

    Boil water, steep tea bag, pour into cup printed; no condiments line.
  2. Step 2: Match output to subclass and hook behavior

    Steep tea bag indicates Tea subclass; missing condiments suggests hook method returned False.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Tea subclass with condiments skipped matches output [OK]
Quick Trick: Missing condiments line -> hook method skipped step [OK]
Common Mistakes:
MISTAKES
  • Assuming condiments always printed regardless of hook.
Trap Explanation:
PITFALL
  • Candidates often fail to reason backward through hook method effect on output.
Interviewer Note:
CONTEXT
  • Tests deep understanding of Template Method output and hook method impact.
Master "Template Method Pattern - Define Skeleton, Override Steps" 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