design-patterns
Design Patterns
A thorough reference covering 26 design patterns organized by intent — creational, structural, and behavioral — featuring PHP 8.3+ implementations, UML guidance, and practical use cases.
Pattern Index
Creational Patterns
- Abstract Factory — Produce families of related objects without specifying their concrete classes → reference
- Builder — Assemble complex objects through a step-by-step process → reference
- Factory Method — Declare an interface for object creation, letting subclasses determine the concrete type → reference
- Prototype — Duplicate existing objects without coupling to their concrete classes → reference
- Singleton — Guarantee that a class has exactly one instance → reference
- Object Pool — Recycle expensive-to-create objects for repeated use → reference
Structural Patterns
- Adapter — Translate one interface into another that clients expect → reference
- Bridge — Separate an abstraction from its implementation so both can evolve independently → reference
- Composite — Arrange objects into tree structures for uniform treatment → reference
- Decorator — Layer new behaviors onto objects dynamically through wrapping → reference
- Facade — Offer a streamlined interface to a complex subsystem → reference
- Flyweight — Minimize memory usage by sharing common state across many objects → reference
- Proxy — Manage access to an object through a surrogate → reference
- Private Class Data — Limit access to class attributes → reference
Behavioral Patterns
- Chain of Responsibility — Route requests through a chain of handlers → reference
- Command — Represent requests as standalone objects → reference
- Interpreter — Establish a grammar representation and an interpreter for it → reference
- Iterator — Walk through elements without revealing the underlying structure → reference
- Mediator — Tame chaotic dependencies through a central coordinator → reference
- Memento — Snapshot and restore object state without breaking encapsulation → reference
- Null Object — Supply a do-nothing default to eliminate null checks → reference
- Observer — Automatically inform dependents when state changes → reference
- State — Change behavior when internal state transitions → reference
- Strategy — Make algorithms interchangeable at runtime → reference
- Template Method — Outline an algorithm skeleton and let subclasses fill in specific steps → reference
- Visitor — Introduce operations to objects without altering their classes → reference
When to Use Which Pattern
| Problem | Pattern |
|---|---|
| Need to create families of related objects | Abstract Factory |
| Complex object construction with many options | Builder |
| Want to defer instantiation to subclasses | Factory Method |
| Need copies of complex objects | Prototype |
| Need exactly one instance globally | Singleton |
| Incompatible interfaces need to work together | Adapter |
| Want to vary abstraction and implementation independently | Bridge |
| Tree structures with uniform treatment | Composite |
| Add responsibilities dynamically without subclassing | Decorator |
| Simplify a complex subsystem interface | Facade |
| Many similar objects consuming too much memory | Flyweight |
| Control access, add lazy loading, or log access | Proxy |
| Multiple handlers for a request, unknown which handles it | Chain of Responsibility |
| Queue, log, or undo operations | Command |
| Need to interpret a simple language/grammar | Interpreter |
| Traverse a collection without exposing internals | Iterator |
| Reduce coupling between many communicating objects | Mediator |
| Need undo/snapshot capability | Memento |
| One-to-many event notification | Observer |
| Object behavior depends on its state | State |
| Need to switch algorithms at runtime | Strategy |
| Algorithm skeleton with customizable steps | Template Method |
| Add operations to object structures without modification | Visitor |
Best Practices
- Favor composition over inheritance — reach for Decorator, Strategy, or Bridge before resorting to deep class hierarchies
- Apply patterns to address real problems, not hypothetical ones
- Leverage PHP 8.3+ features: enums for State, readonly classes for Value Objects, first-class callables for Strategy
- Combine patterns when it makes sense (e.g., Builder + Fluent Interface, Strategy + Factory Method)
- Keep pattern implementations minimal — if the pattern introduces more complexity than it resolves, reconsider the approach
More from krzysztofsurdy/code-virtuoso
symfony-upgrade
Symfony framework version upgrade guide using the deprecation-first approach. Use when the user asks to upgrade Symfony to a new minor or major version, fix deprecation warnings, update Symfony recipes, check bundle compatibility, migrate between LTS versions, or plan a Symfony version migration strategy. Covers PHPUnit Bridge deprecation tracking, recipe updates, bundle compatibility checks, version-specific breaking changes, and the changelog-first upgrade workflow.
87symfony-components
Comprehensive reference for all 38 Symfony framework components with PHP 8.3+ and Symfony 7.x patterns. Use when the user asks to implement, configure, or troubleshoot any Symfony component including HttpFoundation, HttpKernel, DependencyInjection, Form, Validator, Cache, Messenger, Console, EventDispatcher, Workflow, Serializer, Security, Routing, Twig, Doctrine integration, or any other Symfony component. Covers APIs, configuration, best practices, and common pitfalls.
80solid
SOLID principles for object-oriented design with multi-language examples (PHP, Java, Python, TypeScript, C++). Use when the user asks to review SOLID compliance, fix a SOLID violation, evaluate class design, reduce coupling, improve extensibility, or apply Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, or Dependency Inversion principles. Covers motivation, violation detection, refactoring fixes, and real-world trade-offs for each principle.
46agentic-rules-writer
Interactive tool to generate tailored rules and instruction files for any AI coding agent. Use when the user asks to set up agent rules, configure Claude Code instructions, create Cursor rules, write Windsurf rules, generate Copilot instructions, or establish consistent AI coding standards for a team. Supports 13+ agents (Claude Code, Cursor, Windsurf, Copilot, Gemini, Codex, Cline, OpenCode, Continue, Trae, Roo Code, Amp) with global, team-shared, and dev-specific scopes. Defers to the `using-ecosystem` meta-skill for ecosystem discovery (skills, agents, recommendations) and runs an interactive questionnaire for workflow preferences.
46refactoring
Comprehensive skill for 89 refactoring techniques and 22 code smells with practical examples. Use when the user asks to refactor code, detect code smells, improve code quality, reduce complexity, or clean up technical debt. Covers composing methods, moving features between objects, organizing data, simplifying conditionals and method calls, dealing with generalization, and detecting smells across bloaters, OO abusers, change preventers, dispensables, and couplers with before/after comparisons and step-by-step mechanics.
41clean-architecture
Clean Architecture, Hexagonal Architecture (Ports and Adapters), and Domain-Driven Design fundamentals. Use when the user asks to design system architecture, define layer boundaries, apply DDD tactical patterns (entities, value objects, aggregates, repositories), structure a hexagonal application, enforce dependency rules, or evaluate whether a codebase needs architectural refactoring. Covers bounded contexts, use cases, domain services, and framework-independent design.
40