Solid ocp pattern

From paulpas/agent-skill-router · View interactive version

Solid ocp pattern is an AI agent skill from the GitHub repository paulpas/agent-skill-router. Implements the Open/Closed Principle (OCP) from SOLID design principles, allowing classes to be open for extension but closed for modification.

How to use this skill

Skill file

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

Anti-Triggers

Response Profile

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

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

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

MUST NOT DO

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.