Skip to main content

gof-strategy-pattern

Implements the Strategy design pattern allowing the definition of a family of algorithms, encapsulating each one, and making them interchangeable.

설치로 이동

소스 정보

저장소
paulpas/agent-skill-router
최근 소스 활동
2026년 6월 10일 18:00
감지된 SKILL.md 언어
영어
스타
4
포크
1

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
gof-strategy-pattern
description
Implements the Strategy design pattern allowing the definition of a family of algorithms, encapsulating each one, and making them interchangeable.
license
MIT
compatibility
opencode
metadata
{"version":"1.0.0","domain":"architecture","triggers":"strategy pattern, encapsulate algorithms, interchangeable algorithms, gof patterns","archetypes":["educational"],"anti_triggers":["brainstorming","vague ideation"],"response_profile":{"verbosity":"low","directive_strength":"high","abstraction_level":"operational"},"role":"implementation","scope":"implementation","output-format":"code","related-skills":"gof-factory-pattern,"}
# Strategy Pattern Implements the Strategy design pattern allowing the definition of a family of algorithms, encapsulating each one, and making them interchangeable. ## When to Use The When to Use section should outline the scenarios where the Strategy pattern is particularly beneficial: ### Archetypes - **Implementation**: This skill is aimed at implementation to assist developers in applying the Strategy pattern correctly. - **Educational**: It serves as an educational resource, helping users understand when to use the Strategy pattern. ### Anti-Triggers - **Coupling algorithms**: It should prevent triggering in scenarios where algorithms are tightly coupled, negating benefits. ### Response Profile - **Verbosity**: Medium - **Directive Strength**: High - **Abstraction Level**: Tactical archetypes: implementation, educational anti_triggers: coupling algorithms response_profile: verbosity: medium directive_strength: high abstraction_level: tactical - When different variants of an algorithm are needed. - When the choice of the algorithm should be independent of clients that use it. - When you want to avoid using conditionals to switch between algorithms. ## Core Workflow 1. **Define the Strategy Interface**: Create a common interface for all strategies. 2. **Implement Concrete Strategies**: Create concrete classes that implement the strategy interface. 3. **Context Class**: Maintain a reference to a strategy object to delegate behavior. ## Implementation Patterns ### Strategy Pattern Example ```go package main import ( "fmt" ) // Strategy interface type Strategy interface { Execute(int, int) int } // Concrete strategy: Addition type Add struct {} func (Add) Execute(a int, b int) int { return a + b } } // Concrete strategy: Subtraction type Subtract struct {} func (Subtract) Execute(a int, b int) int { return a - b } } // Context type Context struct { strategy Strategy } func (c *Context) SetStrategy(s Strategy) { c.strategy = s } func (c *Context) ExecuteStrategy(a, b int) int { return c.strategy.Execute(a, b) } ``` ### Example Usage ```go package main import ( "fmt" ) func main() { context := &Context{} // Using Addition Strategy context.SetStrategy(Add{}) fmt.Println(context.ExecuteStrategy(5, 3)) // Output: 8 // Using Subtraction Strategy context.SetStrategy(Subtract{}) fmt.Println(context.ExecuteStrategy(5, 3)) // Output: 2 } ``` ## Constraints ### MUST DO - Define clear interfaces for strategies to promote encapsulation. - Ensure clients are decoupled from specific strategy implementations. ### MUST NOT DO - Coupling algorithms within the context class itself. - Hardcoding specific strategy instantiation within client code.
GitHub에서 보기