haonguyen1915/flex-kit/python-design-patterns
Claude Code and agent skill by haonguyen1915/flex-kit
- community
Checking that the SKILL.md file is still in the repository.
Design patterns in their Pythonic form - strategy as a function, factory as a function, adapter, dependency injection by argument, and why singleton is an anti-pattern (a module already is one). Use when choosing a pattern for a local design problem or reviewing over-engineered class hierarchies ported from Java/C++. Not for app-wide layout/layering (see python-architecture) or micro-idioms (see python-idioms).
Install
npx vskill@latest install haonguyen1915/flex-kit/python-design-patternsSKILL.md
The same SKILL.md was published earlier as haonguyen1915/flex-kit/python-design-patterns.
Python Design Patterns
Most GoF patterns exist to work around limits Python doesn't have. Functions are first-class, modules are singletons, duck typing makes interfaces implicit - so the Pythonic form of a pattern is usually smaller than the textbook class diagram. Pick a pattern for the problem, then write its lightest Python form.
Strategy = a function
Don't build a Strategy class hierarchy to swap one algorithm. Pass a callable:
A class strategy earns its keep only when the strategy holds state or needs several methods - otherwise a function (or a Protocol if you need a typed family) is enough.
Factory = a function
A factory is just a function that returns the right object - no AbstractFactory class:
Use it to centralize a construction choice; return a type that satisfies a Protocol so callers depend on the interface, not the concrete class.
Adapter
Wrap a foreign object so it satisfies the interface your code expects - the seam that lets a third-party class fit a Protocol port (see python-architecture) without touching it.
Dependency injection = an argument
Pass dependencies in (constructor or parameter), don't construct them inside. This is DI in Python - no container/framework needed; it's what makes code testable (inject a fake).
Singleton - don't
A Python module is already a singleton (imported once, cached). For "one shared thing", use a module-level value or inject it from the composition root. A Singleton metaclass / __new__ trick adds global mutable state and hidden coupling - an anti-pattern here.
When NOT to pattern
Reach for a pattern only when variation actually exists. A single implementation behind a factory, a one-method Strategy class, or an interface with one impl is speculative generality - delete it. Add the abstraction when the second case arrives, not before.
Review checklist
- [ ] strategy/callback passed as a function, not a one-method class hierarchy
- [ ] factory is a function returning a
Protocoltype, not anAbstractFactory - [ ] adapters isolate third-party APIs behind your own port interface
- [ ] dependencies injected as arguments; nothing constructs its own collaborators
- [ ] no
Singletonclass - module-level value or injection instead - [ ] each abstraction has ≥2 real implementations (else it's speculative)
Red Flags
- a
*Factory/*Strategy/*Managerclass wrapping a single function's worth of logic - a
Singletonmetaclass or__new__guard (hidden global state) - an interface/
Protocolwith exactly one implementer and no second in sight - deep inheritance to share behavior where composition (pass a collaborator) would do
- porting a Java/C++ pattern class-for-class instead of its Python form
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingflex_kit/packs/languages/python/skills/patterns/python-design-patterns/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/haonguyen1915/flex-kit/python-design-patterns)