Install
$ agentstack add skill-luckys-agent-skills-design-patterns-best-practices ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
Design Patterns Best Practices
Use this skill when the main question is not just code quality, but pattern choice and pattern fit.
Working Style
- Start from the problem shape, not from pattern names.
- Prefer the smallest pattern that clarifies variation or collaboration.
- Introduce patterns to reduce coupling and change cost, not to impress readers.
- Keep the domain language more visible than the pattern vocabulary.
- Remove or avoid patterns that explain less than the code they replace.
Pattern Selection Workflow
- Identify the pressure.
- Is the problem construction complexity?
- Is it behavior variation?
- Is it state-dependent behavior?
- Is it external integration mismatch?
- Is it optional layered behavior?
- Choose the likely pattern family.
- Strategy for algorithm or policy variation
- State for behavior driven by state transitions
- Factory for meaningful construction
- Adapter for external interface mismatch
- Decorator for composable behavior layers
- Composite for tree-shaped structures with uniform treatment
- Check the fit.
- Does the pattern remove duplication of knowledge?
- Does it make change local?
- Does it improve object collaboration more than a small refactor would?
- Can the team read it easily?
- Stop if the pattern is heavier than the problem.
Pattern Heuristics
Strategy
Use when behavior varies by policy or algorithm and should be swappable.
State
Use when the same object changes behavior as it transitions through states and the transition rules matter.
Factory
Use when creation logic is complex, repeated, or hides meaningful variation.
Adapter
Use when external APIs do not match the internal model you want.
Decorator
Use when behavior needs to be layered without changing the underlying contract.
Composite
Use when leaf and group objects should answer the same messages.
Observer
Use when one object's state change should trigger reactions in other objects without the source knowing who is listening.
Command
Use when you need to decouple the sender of a request from its executor, or when requests need to be queued, logged, or undone.
Template Method
Use when multiple classes share the same algorithm skeleton but differ in specific steps — and the skeleton should not be changed by subclasses.
Builder
Use when constructing a complex object requires many steps, optional parts, or a specific construction order.
Proxy
Use when you need a surrogate for another object — to defer creation (virtual), control access (protection), or represent a remote resource (remote).
Facade
Use when a complex subsystem needs a simplified interface for callers who don't need its full detail.
Repository
Use when you want to decouple business logic from data access and treat a collection of objects as if it were in memory.
Use ddd-best-practices when the main decision is Aggregate repository semantics, contract ownership, or Repository vs DAO/query service/gateway.
Warning Signs
- The pattern vocabulary dominates the domain language.
- A simple extraction would solve the problem just as well.
- The pattern creates many classes but leaves the coupling intact.
- Inheritance is used where composition would isolate variation better.
- The team has to understand the pattern before it can understand the business rule.
References
- Read
references/pattern-selection-guide.mdfor pattern-to-problem mapping. - Read
references/composition-vs-inheritance.mdfor structural trade-offs. - Read
references/language-examples.mdfor an index of language-specific example files (TypeScript, Java, Python, C#, Ruby, PHP, Go, Rust). - Read
references/go-examples.mdfor Go examples (Strategy/State via interfaces, functional options as Builder, channels as Observer, Result via(value, error)). - Read
references/rust-examples.mdfor Rust examples (traits as Strategy, enums as State/Visitor, trait objects for DI, Result). - Read
references/behavioral-patterns.mdfor Observer, Command, Template Method, Chain of Responsibility, Iterator, Mediator, Visitor, and Memento. - Read
references/creational-patterns.mdfor Builder, Abstract Factory, Factory Method, Singleton, and Prototype trade-offs. - Read
references/structural-patterns.mdfor Proxy, Facade, Bridge, Flyweight, and Adapter — including the Facade vs Adapter distinction. - Read
references/enterprise-patterns.mdfor all 51 PoEAA patterns grouped by category: Domain Logic, Data Source, ORM Behavioral/Structural, Web Presentation, Distribution, Concurrency, Session State, and Base Patterns. - Read
references/patterns-in-practice.mdfor practical heuristics on refactoring toward patterns, Observer lessons, Command Bus, Result pattern, and DI container internals. - Read
references/implementation-patterns.mdfor Kent Beck's micro-level code patterns: naming, composed methods, guard clauses, value objects, lazy/eager initialization, collection accessors, and method objects. - Read
references/clean-architecture.mdfor Clean Architecture layers (Entities, Use Cases, Interface Adapters, Frameworks), the Dependency Rule, Ports & Adapters, Skinny Controllers, and SOLID as architecture enablers. - Read
references/criteria-pattern.mdfor Criteria/query-object decisions, typed predicate ASTs, logical field mappings, backend capabilities, SQL parameterization, joins, pagination, boundary translation, and adapter testing.
Related Skills
- Use
oop-best-practicesfor everyday code quality choices. - Use
refactoring-best-practiceswhen applying a pattern inside risky existing code. - Use
rest-api-best-practiceswhen applying patterns at the HTTP API boundary (Adapter, DTO, Result, Repository). - Use
ddd-best-practicesfor Aggregate-oriented repository contracts and persistence boundaries.
Source Influences
This skill is synthesized from ideas emphasized in:
Head First Design PatternsDrive Into Design PatternsPractical Object-Oriented Design in Rubyby Sandi MetzImplementation Patternsby Kent Beck- CodelyTV Criteria Pattern course (including multi-backend and security counterexamples)
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: luckys
- Source: luckys/agent-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.