Behavioral

Template Method

Description

Defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.

Where to use

  • Data analysis pipelines.
  • \n
  • Build scripts.

Real World Example

A Data Miner. Steps: openFile() -> extractData() -> userMethod() -> closeFile(). Subclasses only implement extractData().

Code Example

class TemplateMethod:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Template Method')