solid-principles

98
13
Source

Enforce SOLID principles (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) in object-oriented design. Use when writing or reviewing classes and modules.

Install

mkdir -p .claude/skills/solid-principles && curl -L -o skill.zip "https://mcp.directory/api/skills/download/77" && unzip -o skill.zip -d .claude/skills/solid-principles && rm skill.zip

Installs to .claude/skills/solid-principles

About this skill

SOLID Principles Skill

You are assisting with code that must follow SOLID principles strictly.

Principles to Enforce

1. Single Responsibility Principle (SRP)

  • Each class should have ONE reason to change
  • Each function should do ONE thing well
  • Separate concerns: business logic, data access, presentation, validation
  • If a class name contains "and" or "or", it likely violates SRP

Red flags:

  • Classes with multiple unrelated methods
  • Functions doing multiple operations
  • Mixed concerns (e.g., validation + persistence in same method)

2. Open/Closed Principle (OCP)

  • Open for extension, closed for modification
  • Use abstract base classes and protocols for extensibility
  • Prefer composition over inheritance
  • New features should be added by extending, not modifying existing code

Patterns to use:

  • Strategy pattern for varying algorithms
  • Template method for varying steps
  • Dependency injection for varying implementations

3. Liskov Substitution Principle (LSP)

  • Subtypes must be substitutable for their base types
  • Derived classes must not strengthen preconditions
  • Derived classes must not weaken postconditions
  • Avoid empty implementations or NotImplementedError in production code

Guidelines:

  • Don't override methods to do nothing
  • Maintain expected behavior contracts
  • Use composition when inheritance doesn't fit naturally

4. Interface Segregation Principle (ISP)

  • Clients should not depend on interfaces they don't use
  • Create focused, cohesive protocols/abstract classes
  • Many small interfaces > one large interface
  • Use Python Protocols for implicit interfaces

Implementation:

  • Split large interfaces into role-specific ones
  • Use Protocol from typing module
  • Avoid "fat" base classes with many optional methods

5. Dependency Inversion Principle (DIP)

  • High-level modules should not depend on low-level modules
  • Both should depend on abstractions (protocols, abstract classes)
  • Abstractions should not depend on details
  • Details should depend on abstractions

Patterns:

  • Constructor injection for required dependencies
  • Use abstract base classes or Protocols
  • Depend on interfaces, not concrete implementations

Code Review Checklist

When reviewing or writing code, check:

  • Does each class have a single, clear responsibility?
  • Can new behavior be added without modifying existing code?
  • Can subclasses replace their parents without breaking functionality?
  • Are interfaces focused and cohesive?
  • Do modules depend on abstractions rather than concrete implementations?

Practical Application for Admission Rules System

For the Norwegian admission rules system:

  • SRP: Separate rule evaluation, grade calculation, quota management
  • OCP: Make rules extensible (new admission rules without changing core engine)
  • LSP: All rule types should be substitutable
  • ISP: Separate interfaces for validators, calculators, reporters
  • DIP: Depend on abstract rule interfaces, not concrete rule implementations

Response Format

When applying SOLID principles:

  1. Identify which principle(s) are relevant
  2. Explain the violation if any exists
  3. Provide refactored code following the principle(s)
  4. Explain the benefit of the refactoring

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

282789

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

209415

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

201286

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

213231

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

169197

rust-coding-skill

UtakataKyosui

Guides Claude in writing idiomatic, efficient, well-structured Rust code using proper data modeling, traits, impl organization, macros, and build-speed best practices.

165173

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.