Table of Contents

Class TemplateMethod<TInput, TResult>

Abstract base class for the Template Method pattern. Defines the skeleton of an algorithm in Execute(TInput) (the template method) while delegating the concrete steps to subclasses via abstract methods. This lets subclasses change specific parts of the algorithm without altering its overall structure.

public abstract class TemplateMethod<TInput, TResult>

Type Parameters

TInput

The type of data the algorithm operates on.

TResult

The type produced at the end of the algorithm.

Inheritance
TemplateMethod<TInput, TResult>
Derived
Inherited Members

Methods

Execute(TInput)

Runs the full algorithm: pre-process → process → post-process. Subclasses must not override this method; instead override the individual steps.

public TResult Execute(TInput input)

Parameters

input TInput

The data to process.

Returns

TResult

The final result after all steps complete.

PostProcess(TResult)

Step 3: Post-processing logic run after the main processing. Override to log, cache, or dispatch the result.

protected abstract void PostProcess(TResult result)

Parameters

result TResult

The result produced by Process(TInput).

PreProcess(TInput)

Step 1: Preparation logic run before the main processing. Override to validate, sanitise, or log incoming data.

protected abstract void PreProcess(TInput input)

Parameters

input TInput

The raw input before processing.

Process(TInput)

Step 2: The core algorithm. Must be implemented by every subclass.

protected abstract TResult Process(TInput input)

Parameters

input TInput

The (pre-processed) input to transform.

Returns

TResult

The intermediate result passed to PostProcess(TResult).