Skip to main content

solid-ocp-pattern

Implements the Open/Closed Principle (OCP) from SOLID design principles, allowing classes to be open for extension but closed for modification.

설치로 이동

소스 정보

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

설치 방법

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

소스 파일 검토

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

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
solid-ocp-pattern
description
Implements the Open/Closed Principle (OCP) from SOLID design principles, allowing classes to be open for extension but closed for modification.
license
MIT
compatibility
opencode
metadata
{"version":"1.0.0","domain":"architecture","triggers":"open closed principle, solid principles, extend, modify","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":"solid-srp-pattern,"}
# Open/Closed Principle (OCP) archetypes: implementation, educational anti_triggers: modifying classes response_profile: verbosity: medium directive_strength: high abstraction_level: tactical Implements the Open/Closed Principle (OCP) from SOLID design principles, allowing classes to be open for extension but closed for modification. ## When to Use This section should elaborate on the specific circumstances in which the Open/Closed Principle proves most advantageous: ### Archetypes - **Implementation**: This skill guides the user on applying the Open/Closed Principle in their projects. - **Educational**: Aims to teach developers about the benefits of the Open/Closed Principle. ### Anti-Triggers - **Modifying classes**: Must avoid contexts where there is a focus on altering existing classes without the extension approach. ### Response Profile - **Verbosity**: Medium - **Directive Strength**: High - **Abstraction Level**: Tactical - When you anticipate a need to add new functionalities without changing existing code. - To prevent bugs introduced by modifications to existing code. - To follow the DRY principle while maintaining flexibility in the code. ## Core Workflow 1. **Define an Interface**: Create an interface that outlines the behavior without implementing it. 2. **Create Concrete Implementations**: Develop specific implementations of the interface. 3. **Integrate New Features through Composition**: Use composition to extend behaviors without altering existing code. ## Implementation Patterns ### OCP Example ```go package main import ( "fmt" ) // Shape interface defines the behavior type Shape interface { Area() float64 } // Circle struct is a shape type Circle struct { Radius float64 } // Rectangle struct is another shape type Rectangle struct { Length, Width float64 } func (c Circle) Area() float64 { return 3.14 * c.Radius * c.Radius } } func (r Rectangle) Area() float64 { return r.Length * r.Width } } // TotalArea computes the total area of all shapes func TotalArea(shapes ...Shape) float64 { total := 0.0 for _, shape := range shapes { total += shape.Area() } return total } ``` ### Example Usage ```go package main func main() { circle := Circle{Radius: 10} rectangle := Rectangle{Length: 5, Width: 6} shapes := []Shape{circle, rectangle} total := TotalArea(shapes...) fmt.Println("Total Area:", total) // Output: Total Area: 314.0 } ``` ## Constraints ### MUST DO - Ensure classes implement interfaces instead of altering existing classes. - Use the interface-based extension for adding new functionality without modifying existing details. ### MUST NOT DO - Modify existing classes directly for new functionality. - Break the existing interface contract when implementing new features.
GitHub에서 보기