Back to Browse

Design Patterns Lab — Lecture 7: Template Method vs Strategy Pattern

38 views
Premiered May 9, 2026
54:36

In this lecture, we explore two important Behavioral Design Patterns: Template Method and Strategy Pattern, and understand how they solve different types of design problems in real-world systems. We start with the Template Method Pattern, where the focus is on designing systems with a fixed workflow while allowing flexibility in how each step is implemented. Using a university submission processing system, we demonstrate how different departments follow the same process but apply different logic internally. Then, we move to the Strategy Pattern, where the focus shifts to runtime flexibility. Instead of fixing the workflow, we allow the system to dynamically switch between different algorithms using composition. We build a scoring system where behavior can change at runtime without modifying the main logic. Throughout the lecture, we emphasize the key difference between the two patterns: - Template Method → fixed structure, flexible steps (inheritance) - Strategy → flexible behavior, dynamic switching (composition) This lecture follows a clear learning flow: Problem → Pattern Design → Implementation → Comparison → Real-world Understanding 📚 Topics Covered • Behavioral Design Patterns overview • Template Method Pattern (concept + structure) • Fixed workflow design • Abstract classes and method control • Strategy Pattern (concept + structure) • Runtime behavior switching • Composition vs Inheritance • Eliminating conditional logic using polymorphism • Real-world system design examples • Strategy vs Template Method comparison 💡 Key Takeaways - Template Method enforces a consistent process structure - Strategy enables dynamic behavior switching at runtime - Inheritance controls structure, composition controls behavior - Both patterns reduce code duplication and improve maintainability - Choosing the right pattern depends on what needs to vary 📂 Repositories (Code + Activities) 🔹 Template Method: https://github.com/Maryam-Skaik/design-patterns-lab-template-method 🔹 Strategy Pattern: https://github.com/Maryam-Skaik/design-patterns-lab-strategy 🧪 Practice Activities - Design a Hospital Patient Processing System using Template Method Pattern - Build a Dynamic Payment System using Strategy Pattern - Compare both designs and identify when to use each pattern

Download

0 formats

No download links available.

Design Patterns Lab — Lecture 7: Template Method vs Strategy Pattern | NatokHD