From harness-claude
Defines the skeleton of an algorithm in a base class and lets subclasses override specific steps. Useful when multiple classes share the same algorithmic structure but differ in certain steps.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:js-template-method-patternThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Define the skeleton of an algorithm in a base class and let subclasses override specific steps
Define the skeleton of an algorithm in a base class and let subclasses override specific steps
class DataProcessor {
process(data) {
const validated = this.validate(data);
const transformed = this.transform(validated);
return this.format(transformed);
}
validate(data) {
return data;
} // default: no-op
transform(data) {
throw new Error('Subclass must implement transform()');
}
format(data) {
return JSON.stringify(data);
} // default: JSON
}
class CSVProcessor extends DataProcessor {
transform(data) {
return data.map((row) => row.join(','));
}
format(data) {
return data.join('\n');
}
}
The Template Method pattern uses inheritance to vary parts of an algorithm. The base class defines the algorithm's skeleton, and subclasses fill in the blanks. This is the inverse of the Strategy pattern — Template Method uses inheritance, Strategy uses composition.
Trade-offs:
When NOT to use:
https://patterns.dev/javascript/template-method-pattern
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeImplements the Template Method design pattern to define algorithm skeletons in base classes with abstract steps filled by subclasses. Useful for parsers, importers, and test frameworks.
Defines an algorithm skeleton in a base class with abstract steps for subclasses to override. Use when multiple classes share the same structure but differ in specific steps.
Generates Template Method pattern for PHP 8.4: abstract algorithm skeleton with customizable steps, concrete implementations, hooks, optional value objects, and unit tests. For reusable algorithms with variants like data processing.