python-design-patterns
하는 일
이 스킬은 Python 코드를 이해하고, 테스트하고, 바꾸기 쉽도록 정리하도록 돕습니다. 단순함을 유지하고 각 코드 조각이 하나의 역할만 맡도록 하는 원칙을 가르칩니다.
사용하는 경우
- ✓새 프로젝트나 그 일부를 시작할 때.
- ✓기존 코드가 너무 지저분해서 바꾸기 어려울 때.
- ✓코드를 새 구조로 만들지, 아니면 반복해서 쓸지 결정할 때.
스킬 링크
https://github.com/wshobson/agents/blob/main/plugins/python-development/skills/python-design-patterns/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“Python 코드를 어떻게 정리하면 유지 관리하기 더 쉬울까요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 '단순하게 유지하라'와 '각 부분은 하나의 책임만 갖는다' 같은 원칙을 따르도록 제안합니다. 또한 복잡한 계층 구조를 만드는 대신 객체를 조합하는 방법과, 예시가 세 개 생길 때까지 새 구조를 만들기를 기다리는 방법도 가르칩니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Python Design Patterns
Write maintainable Python code using fundamental design principles. These patterns help you build systems that are easy to understand, test, and modify.
When to Use This Skill
- Designing new components or services
- Refactoring complex or tangled code
- Deciding whether to create an abstraction
- Choosing between inheritance and composition
- Evaluating code complexity and coupling
- Planning modular architectures
Core Concepts
1. KISS (Keep It Simple)
Choose the simplest solution that works. Complexity must be justified by concrete requirements.
2. Single Responsibility (SRP)
Each unit should have one reason to change. Separate concerns into focused components.
3. Composition Over Inheritance
Build behavior by combining objects, not extending classes.
4. Rule of Three
Wait until you have three instances before abstracting. Duplication is often better than premature abstraction.
Quick Start
# Simple beats clever
# Instead of a factory/registry pattern:
FORMATTERS = {"json": JsonFormatter, "csv": CsvFormatter}
def get_formatter(name: str) -> Formatter:
return FORMATTERS[name]()
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices Summary
- Keep it simple - Choose the simplest solution that works
- Single responsibility - Each unit has one reason to change
- Separate concerns - Distinct layers with clear purposes
- Compose, don't inherit - Combine objects for flexibility
- Rule of three - Wait before abstracting
- Keep functions small - 20-50 lines (varies by complexity), one purpose
- Inject dependencies - Constructor injection for testability
- Delete before abstracting - Remove dead code, then consider patterns
- Test each layer - Isolated tests for each concern
- Explicit over clever - Readable code beats elegant code
Troubleshooting
A class is growing and seems to have multiple responsibilities, but splitting it feels wrong. Apply the "reason to change" test: list every change that could require editing this class. If the list has items from different domains (e.g., HTTP parsing AND business rules AND formatting), split it. If all changes stem from the same domain concern, the class may be appropriately sized.
Injecting all dependencies through the constructor is producing constructors with 7+ parameters. This is a sign of too many responsibilities in one class, not a problem with dependency injection. Split the class into smaller units first, then each constructor naturally becomes smaller.
Composition is producing deeply nested wrapper objects that are hard to trace. Keep the composition shallow (2-3 levels). If wrapping is the only mechanism, consider whether a Protocol-based approach or simple function composition would be cleaner than a chain of decorator objects.
The rule of three says not to abstract yet, but the duplication is causing bugs when one copy is updated but not the other. Duplication that diverges in dangerous ways should be abstracted sooner. The rule of three is a heuristic, not a law. If the copies are already diverging incorrectly, extract immediately and add a test that exercises the shared behavior.
A service layer is importing from the API layer, breaking the dependency direction. This is a layering violation. The service layer must not import from handlers. Introduce a shared types/models layer that both can import from, keeping the dependency arrow pointing downward (API → Service → Repository).
Related Skills
- python-testing-patterns — Test each layer in isolation using the dependency injection structure established here
- python-project-structure — Organize modules and directory layout so layer boundaries are explicit from the start
자주 묻는 질문
'상속보다 조합'은 무슨 뜻인가요?
기존 클래스를 상속받는 새 클래스를 만드는 대신, 기존 객체를 결합해 기능을 만드는 것이 더 낫다는 뜻입니다.
언제 새 추상화를 만들어야 하나요?
일반적인 규칙은 비슷한 예시가 세 개 생길 때까지 기다리는 것입니다. 그 전에는 약간의 코드를 반복하는 것이 성급한 추상화보다 간단하고 안전할 수 있습니다.
코드가 너무 커지고 지저분해졌어요. 어떻게 해야 하나요?
코드를 더 작은 부분으로 나누세요. 각 부분은 바뀔 이유가 하나만 있어야 합니다. 그러면 각 부분이 더 집중되고 관리하기 쉬워집니다.
상세 정보
작성자의 원본 설명
Python design patterns including KISS, Separation of Concerns, Single Responsibility, and composition over inheritance. Use this skill when designing a new service or component from scratch and choosing how to layer responsibilities, when refactoring a God class or monolithic function that has grown too large, when deciding whether to add a new abstraction or live with duplication, when evaluating
repo: wshobson/agents
인기도
- GitHub 스타
- 41k
- 순위
- #6760
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
screen-reader-testing
41k에이전트가 스크린 리더로 웹사이트를 테스트해 접근성을 확인하도록 돕습니다.
wcag-audit-patterns
41k에이전트가 WCAG 지침에 따라 웹사이트의 접근성을 감사하고 문제를 고치도록 돕습니다.
multi-reviewer-patterns
41k에이전트가 병렬 코드 리뷰를 조율하고, 중복된 발견 사항을 정리하며, 보고서를 통합하도록 돕습니다.
parallel-debugging
41k에이전트가 병렬 조사와 근본 원인 분석으로 복잡한 문제를 디버그하도록 돕습니다.