About laravel:strategy-pattern
A Laravel skill for structuring interchangeable implementations behind a shared interface. It helps developers select behavior by a key or context and centralize construction in a factory.
Key features
- 01Shared interface for strategies
- 02Multiple interchangeable implementations
- 03Selection by key or context
- 04Factory registered in a service provider
Use cases
- 01Selecting country-specific tax calculations
- 02Choosing behavior based on runtime context
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ jpcaparas/ superpowers-laravel --skill laravel:strategy-patternAfter installing, type/laravel:strategy-patternin Claude Code to confirm it loaded.
Details
From the project READMEStrategy 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.
Comments
Markdown supported