strategy-registry-pattern

Implements pluggable Strategy, Registry, and Handler patterns for Spring Boot microservices.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill strategy-registry-pattern-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: strategy-registry-pattern
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/strategy-registry-pattern
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill strategy-registry-pattern-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Hardcoding if/else or switch logic to select between multiple implementations of the same concern violates the Open/Closed Principle and forces risky edits to existing dispatcher code every time a new behavior is added. ## Core Features & Use Cases - Pluggable Architecture Blueprint: Defines the Handler/Filter, Resolver, Registry, Strategy interface, Parser, and Helper components with concrete Java code examples for each. - Runtime Strategy Selection: Routes requests to the correct implementation based on context such as URI patterns, caller type, query parameters, or API version. - Use Case: When adding a new permission check for a new caller type, you create one new @Component strategy class and its tests — the Handler, Registry, and all existing strategies remain untouched. ## Quick Start Apply the strategy-registry-pattern skill to refactor this class so new behaviors are added as new strategy components without modifying the dispatcher.

Frequently Asked Questions about strategy-registry-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement the Strategy pattern in Spring Boot?

Define a Strategy interface with a canHandle discriminator method, implement concrete strategies as @Component beans, and inject List<Strategy> into a Registry that filters by canHandle. Spring auto-discovers all implementations, so new strategies require no changes to existing code.

How to select a strategy at runtime based on request context?

Use a Resolver component that extracts a discriminator from the request, such as a URI pattern, caller type, or query parameter. The Registry then routes that discriminator to the matching strategy via its canHandle method, returning null when nothing matches.

When should I use a Filter versus a Handler for cross-cutting concerns?

Use a Filter extending OncePerRequestFilter for request-scoped concerns like metrics or logging that apply to every request. Use a Handler invoked explicitly in business logic for synchronous operations like permission checks or entity-to-DTO mapping.

When is the Strategy Registry pattern overkill?

Avoid it when only one implementation exists, when a simple two or three case if/else suffices, or when compile-time selection via Spring @Conditional beans is enough. It also fits poorly when strategies share tightly coupled state.

Why should parsers return sentinel values instead of null?

Parsers return non-blank sentinels like UNKNOWN or DEFAULT so downstream tag building and metrics recording never break on extraction failures. Exceptions are caught, logged with log.error, and converted to the sentinel value.