noartem

laravel-strategy-pattern

by @noartem in Tools
1
0
# Install this skill:
npx skills add noartem/skills --skill "laravel-strategy-pattern"

Install specific skill from multi-skill repository

# Description

Use the Strategy pattern to select behavior at runtime; bind multiple implementations to a shared interface

# SKILL.md


name: laravel-strategy-pattern
description: Use the Strategy pattern to select behavior at runtime; bind multiple implementations to a shared interface


Strategy Pattern

Create a common interface and multiple implementations. Choose a strategy by key or context.

interface TaxCalculator { public function for(int $cents): int; }
final class NzTax implements TaxCalculator { /* ... */ }
final class AuTax implements TaxCalculator { /* ... */ }

final class TaxFactory {
  public function __construct(private array $drivers) {}
  public function forCountry(string $code): TaxCalculator { return $this->drivers[$code]; }
}

Register in a service provider and inject the factory where needed.

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.