As an example, the TemplateMethod project from the Template method folder implements two specialized versions of a shared template method. The complete definition of the base object and template method is shown here:
type TDataAggregatorTemplate = class protected procedure CloseDataSource; virtual; abstract; function GetNextValue(var value: integer): boolean; virtual; abstract; function OpenDataSource: boolean; virtual; abstract; public function CalculateAverage: real; end;function TDataAggregatorTemplate.CalculateAverage: real;var sum: integer; total: integer; value: integer;begin if not OpenDataSource then raise Exception.Create('Failed!'); try total := 0; sum := 0; while GetNextValue(value) do begin Inc(total); ...