🎨 Design Patterns (Gang of Four)
Intermediate
What is the Template Method design pattern?
Answer
The Template Method pattern defines the skeleton of an algorithm in a base class, deferring some steps to subclasses. The base class method calls abstract or overridable "hook" methods in a fixed order. Subclasses fill in the specific steps without changing the overall algorithm structure. For example, a data mining framework might define: openFile() → extractData() → parseData() → analyzeData() → closeFile(). The base class implements the invariant steps; each concrete miner implements extractData() and parseData() for its specific format (CSV, XML, PDF). This is the foundation of the Hollywood Principle: "Don't call us, we'll call you."
More Design Patterns (Gang of Four) Questions
View all →- Intermediate What is the Visitor design pattern?
- Intermediate What is the difference between Factory Method and Abstract Factory?
- Intermediate When should you NOT use design patterns?
- Intermediate How are the Gang of Four patterns categorized?
- Intermediate How are GoF patterns used in real-world frameworks?