Python SOLID Design
Announce
Using the python-solid-design skill for OOP design/review.
Read order
- Tier-A checklist below — apply on design and review.
- Open the principle file that matches the smell:
- srp.md — Single Responsibility
- ocp.md — Open/Closed
- lsp.md — Liskov Substitution
- isp.md — Interface Segregation
- dip.md — Dependency Inversion
- examples.md — Violation / Compliant pairs when refactoring
- references.md — definitions, smell map, Python idioms
When to apply
Apply when adding or changing classes/modules, especially:
- God-objects mixing domain, I/O, payment, and notifications
- Growing
if/elifswitches on type or mode - Subclasses that raise, no-op, or change base contracts
- Fat interfaces forcing unused methods
- High-level policy that constructs concrete collaborators
Skip forcing SOLID onto tiny one-off scripts with no extension or test pressure.
Review workflow
- Name each class’s responsibility and reasons to change.
- Prefer new subtypes / strategies over editing closed, tested branches.
- Check subtype contracts (inputs accepted, outputs promised, no surprise exceptions).
- Split fat interfaces; clients depend only on methods they use.
- Depend on abstractions; inject collaborators (constructor injection).
- After structural refactors, format/lint with the project style skill when relevant.
Tier A — enforce on OOP edits
- S — One concept / one primary reason to change per class
- O — Extend behavior with new code; avoid modifying closed switches for every variant
- L — Subtypes must be safely substitutable for their base/Protocol
- I — Prefer small, role-specific interfaces over one kitchen-sink ABC
- D — High-level modules depend on abstractions, not concrete low-level types
Anti-overengineering
- SRP means one concept, not one method per class — avoid a fragmented sea of single-method types.
- Do not invent an ABC/Protocol for a single forever-stable implementation.
- Prefer composition when inheritance breaks substitutability.
- SOLID guides design under change pressure; clarity beats ceremony.
Additional resources
- references.md
- srp.md
- ocp.md
- lsp.md
- isp.md
- dip.md
- examples.md