MediumPro challengePythonJavaScriptTypeScript
Template Method
TypeScriptDesign PatternsBehavioralTemplate Method
Define the skeleton of an algorithm in a base class, deferring only specific steps to subclasses — every beverage boils water and pours a cup the same way, but brewing and condiments differ.
Implement `Tea`/`Coffee`, overriding only brew() and addCondiments() — Beverage.prepare() (already wired) calls them in a fixed sequence.
solve('tea') → ['Boil water', 'Steep tea', 'Pour in cup', 'Add lemon']
Sample tests
Test #1Tea preparation steps
Input: ["tea"]
Output: ["Boil water","Steep tea","Pour in cup","Add lemon"]
Test #2Coffee preparation steps
Input: ["coffee"]
Output: ["Boil water","Brew coffee grounds","Pour in cup","Add sugar and milk"]
Test #3Deterministic — repeated tea call
Input: ["tea"]
Output: ["Boil water","Steep tea","Pour in cup","Add lemon"]