create-template-method

Generates Template Method pattern for PHP 8.4. Creates abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure. Includes unit tests.

59 stars

Best use case

create-template-method is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Generates Template Method pattern for PHP 8.4. Creates abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure. Includes unit tests.

Teams using create-template-method should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/create-template-method/SKILL.md --create-dirs "https://raw.githubusercontent.com/dykyi-roman/awesome-claude-code/main/skills/create-template-method/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/create-template-method/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How create-template-method Compares

Feature / Agentcreate-template-methodStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generates Template Method pattern for PHP 8.4. Creates abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure. Includes unit tests.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Template Method Pattern Generator

Creates Template Method pattern infrastructure for algorithm skeletons with customizable steps.

## When to Use

| Scenario | Example |
|----------|---------|
| Common algorithm structure | Data import/export with format variations |
| Controlled extension points | Report generation with customizable sections |
| Code reuse across variants | Order processing with type-specific steps |
| Invariant parts protection | Template rendering with hooks |

## Component Characteristics

### Abstract Template Class
- Defines algorithm skeleton
- Implements invariant steps
- Declares abstract/hook methods
- Calls methods in sequence

### Concrete Implementations
- Override specific steps
- Provide algorithm variants
- Inherit common behavior
- Maintain overall structure

### Hook Methods
- Optional override points
- Default empty implementation
- Allow customization
- Don't break flow

---

## Generation Process

### Step 1: Generate Abstract Template

**Path:** `src/Domain/{BoundedContext}/Template/`

1. `Abstract{Name}Template.php` — Algorithm skeleton with template method

### Step 2: Generate Concrete Templates

**Path:** `src/Domain/{BoundedContext}/Template/` or `src/Application/{BoundedContext}/`

1. `{Variant1}{Name}Template.php` — First variant implementation
2. `{Variant2}{Name}Template.php` — Second variant implementation
3. `{Variant3}{Name}Template.php` — Third variant implementation

### Step 3: Generate Support Classes (Optional)

**Path:** `src/Domain/{BoundedContext}/ValueObject/`

1. `{Name}Result.php` — Result value object
2. `{Name}Config.php` — Configuration value object

### Step 4: Generate Tests

1. `{Variant}{Name}TemplateTest.php` — Individual template tests
2. `Abstract{Name}TemplateTest.php` — Template skeleton tests

---

## File Placement

| Component | Path |
|-----------|------|
| Abstract Template | `src/Domain/{BoundedContext}/Template/` |
| Concrete Templates (Domain logic) | `src/Domain/{BoundedContext}/Template/` |
| Concrete Templates (App logic) | `src/Application/{BoundedContext}/` |
| Unit Tests | `tests/Unit/Domain/{BoundedContext}/Template/` |

---

## Naming Conventions

| Component | Pattern | Example |
|-----------|---------|---------|
| Abstract | `Abstract{Name}Template` | `AbstractDataImporterTemplate` |
| Concrete | `{Variant}{Name}Template` | `CsvDataImporterTemplate` |
| Template Method | `execute()` or `process()` | `execute()` |
| Hook Method | `before{Step}()`, `after{Step}()` | `beforeValidation()` |
| Test | `{ClassName}Test` | `CsvDataImporterTemplateTest` |

---

## Quick Template Reference

### Abstract Template

```php
abstract readonly class Abstract{Name}Template
{
    public function execute({InputType} $input): {OutputType}
    {
        $this->validate($input);
        $data = $this->extract($input);
        $transformed = $this->transform($data);
        $result = $this->load($transformed);
        $this->afterLoad($result);

        return $result;
    }

    abstract protected function extract({InputType} $input): array;
    abstract protected function transform(array $data): array;

    protected function validate({InputType} $input): void
    {
        // Default validation
    }

    protected function afterLoad({OutputType} $result): void
    {
        // Hook method - optional override
    }
}
```

### Concrete Template

```php
final readonly class {Variant}{Name}Template extends Abstract{Name}Template
{
    protected function extract({InputType} $input): array
    {
        // Variant-specific extraction
    }

    protected function transform(array $data): array
    {
        // Variant-specific transformation
    }
}
```

---

## Usage Example

```php
// Create templates for different formats
$csvImporter = new CsvDataImporterTemplate();
$jsonImporter = new JsonDataImporterTemplate();
$xmlImporter = new XmlDataImporterTemplate();

// Use same interface
$result = $csvImporter->execute($fileContent);
```

---

## Common Template Method Variants

| Domain | Variants |
|--------|----------|
| Data Import | CSV, JSON, XML, Excel |
| Report Generation | PDF, Excel, HTML, Email |
| Order Processing | Standard, Express, International |
| Document Rendering | Markdown, LaTeX, HTML |
| Payment Flow | Card, Bank Transfer, Digital Wallet |

---

## Anti-patterns to Avoid

| Anti-pattern | Problem | Solution |
|--------------|---------|----------|
| Too many abstract methods | Hard to implement | Use hook methods with defaults |
| Public template steps | Breaks encapsulation | Make steps protected/private |
| Mutable state | Side effects | Use readonly classes, pass data |
| Deep inheritance | Complexity | Limit to 2-3 levels max |
| Breaking LSP | Inconsistent behavior | Maintain contract in overrides |

---

## References

For complete PHP templates and examples, see:
- `references/templates.md` — Abstract Template, Concrete Template, Hook Methods templates
- `references/examples.md` — DataImporter, ReportGenerator, OrderProcessor with tests

Related Skills

troubleshooting-template

59
from dykyi-roman/awesome-claude-code

Generates troubleshooting guides and FAQ sections for PHP projects. Creates problem-solution documentation.

mermaid-template

59
from dykyi-roman/awesome-claude-code

Generates Mermaid diagrams for technical documentation. Provides templates for flowcharts, sequence diagrams, class diagrams, ER diagrams, and C4 models.

getting-started-template

59
from dykyi-roman/awesome-claude-code

Generates Getting Started guides for PHP projects. Creates step-by-step tutorials for first-time users.

explain-output-template

59
from dykyi-roman/awesome-claude-code

Output format templates for all 5 explanation modes — quick (compact), deep (full analysis with diagrams), onboarding (project guide), business (non-technical), qa (interactive Q&A).

create-visitor

59
from dykyi-roman/awesome-claude-code

Generates Visitor pattern for PHP 8.4. Creates operations on object structures without modifying element classes, with visitor interface, concrete visitors, and visitable elements. Includes unit tests.

create-value-object

59
from dykyi-roman/awesome-claude-code

Generates DDD Value Objects for PHP 8.4. Creates immutable, self-validating objects with equality comparison. Includes unit tests.

create-use-case

59
from dykyi-roman/awesome-claude-code

Generates Application Use Cases for PHP 8.4. Creates orchestration services that coordinate domain objects, handle transactions, and dispatch events. Includes unit tests.

create-unit-test

59
from dykyi-roman/awesome-claude-code

Generates PHPUnit unit tests for PHP 8.4. Creates isolated tests with AAA pattern, proper naming, attributes, and one behavior per test. Supports Value Objects, Entities, Services.

create-unit-of-work

59
from dykyi-roman/awesome-claude-code

Generates Unit of Work pattern components for PHP 8.4. Creates transactional consistency infrastructure with aggregate tracking, flush/rollback, domain event collection, and unit tests.

create-timeout

59
from dykyi-roman/awesome-claude-code

Generates Timeout pattern components for PHP 8.4. Creates execution time limit infrastructure with configurable timeouts, fallback support, stream timeouts, and unit tests.

create-test-double

59
from dykyi-roman/awesome-claude-code

Generates test doubles (Mocks, Stubs, Fakes, Spies) for PHP 8.4. Creates appropriate double type based on testing needs with PHPUnit MockBuilder patterns.

create-test-builder

59
from dykyi-roman/awesome-claude-code

Generates Test Data Builder and Object Mother patterns for PHP 8.4. Creates fluent builders with sensible defaults and factory methods for test data creation.