用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill solid-principles命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | SOLID Principles |
| description | Five design principles for writing maintainable, extensible object-oriented software |
| category | software-development |
I provide five fundamental design principles that help software developers create systems that are easy to maintain, understand, and extend. SOLID is an acronym representing Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion. These principles guide object-oriented design toward more flexible, robust code that can evolve over time without requiring constant rewrites.
Apply SOLID principles when designing new classes, refactoring existing code, or reviewing object-oriented architectures. They are especially valuable in large codebases with multiple developers, where consistent design standards prevent chaos. Use them when you need your code to be testable, when requirements change frequently, or when building frameworks/libraries that other code will depend on. Avoid applying them dogatically to trivial code or one-off scripts.
from abc import ABC, abstractmethod
from datetime import datetime
from typing import Protocol
class JournalEntry:
def __init__(self, title: str, content: str):
self.title = title
self.content = content
self.created_at = datetime.now()
self.entries: list['JournalEntry'] = []
def add_entry(self, entry: 'JournalEntry') -> None:
self.entries.append(entry)
class Persistence(Protocol):
@abstractmethod
def save(self, filename: str) -> None:
pass
class FilePersistence:
def save(self, journal: JournalEntry, filename: str) -> None:
with open(filename, 'w') as f:
f.write(f"{journal.title}\n{journal.content}")
class :
() -> :
()
:
():
.entries: [JournalEntry] = []
.persister: Persistence | =
() -> JournalEntry:
entry = JournalEntry(title, content)
.entries.append(entry)
entry
() -> :
.persister:
.persister.save(, filename)
from abc import ABC, abstractmethod
from typing import Protocol
class DiscountStrategy(Protocol):
@abstractmethod
def calculate(self, price: float) -> float:
pass
class RegularDiscount:
def calculate(self, price: float) -> float:
return price * 0.9
class SilverDiscount:
def calculate(self, price: float) -> float:
return price * 0.85
class GoldDiscount:
def calculate(self, price: float) -> float:
return price * 0.8
class PriceCalculator:
def __init__(self, discount: DiscountStrategy):
self.discount = discount
def calculate_final_price(self, price: float) -> :
.discount.calculate(price)
calculator = PriceCalculator(GoldDiscount())
()
from abc import ABC, abstractmethod
from typing import Protocol
class Bird(Protocol):
@abstractmethod
def fly(self) -> None:
pass
@abstractmethod
def eat(self) -> None:
pass
class Sparrow:
def fly(self) -> None:
print("Sparrow flying")
def eat(self) -> None:
print("Sparrow eating")
class Ostrich:
def eat(self) -> None:
print("Ostrich eating")
def run(self) -> None:
print("Ostrich running")
class FlightfulBird(ABC):
@abstractmethod
def fly() -> :
():
() -> :
():
() -> :
()
() -> :
()
() -> :
bird.fly()
make_bird_fly(Eagle())
from abc import ABC, abstractmethod
from typing import Protocol
class Printer(Protocol):
@abstractmethod
def print(self, document: str) -> None:
pass
class Scanner(Protocol):
@abstractmethod
def scan(self, document: str) -> None:
pass
class Fax(Protocol):
@abstractmethod
def fax(self, document: str) -> None:
pass
class OldPrinter:
def print(self, document: str) -> None:
print(f"Printing: {document}")
class ModernPrinter:
def print(self, document: str) -> None:
print(f"Printing: ")
() -> :
()
() -> :
()
:
():
.printer = printer
.scanner = scanner
() -> :
.printer.(doc)
() -> :
.scanner.scan(doc)
from abc import ABC, abstractmethod
from typing import Protocol
class MessageSender(Protocol):
@abstractmethod
def send(self, message: str, recipient: str) -> bool:
pass
class EmailSender:
def send(self, message: str, recipient: str) -> bool:
print(f"Sending email to {recipient}: {message}")
return True
class SMSender:
def send(self, message: str, recipient: str) -> bool:
print(f"Sending SMS to {recipient}: {message}")
return True
class NotificationService:
def __init__(self, sender: MessageSender):
self.sender = sender
def send_notification(self, message: , recipient: ) -> :
.sender.send(message, recipient)
:
():
.name = name
.email = email
.phone = phone
email_service = EmailSender()
notification = NotificationService(email_service)
notification.send_notification(, )