Class TemplateMethod<TInput, TResult>
- Namespace
- WitShells.DesignPatterns.Core
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
TInputThe type of data the algorithm operates on.
TResultThe 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
inputTInputThe 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
resultTResultThe 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
inputTInputThe raw input before processing.
Process(TInput)
Step 2: The core algorithm. Must be implemented by every subclass.
protected abstract TResult Process(TInput input)
Parameters
inputTInputThe (pre-processed) input to transform.
Returns
- TResult
The intermediate result passed to PostProcess(TResult).