What are PHP design patterns for solving common problems?
Why Interviewers Ask This
Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.
Answer
Common PHP design patterns: Singleton (one instance — use with caution, makes testing hard), Factory/Abstract Factory (encapsulate object creation), Builder (construct complex objects step-by-step), Repository (abstract data access), Observer/Event Dispatcher (publish-subscribe), Strategy (swap algorithms at runtime), Decorator (add behavior dynamically), Adapter (wrap incompatible interfaces), Facade (simplify a complex subsystem — Laravel's facades), Proxy (control access to an object), Command (encapsulate a request as an object — used in command buses), and Specification (encapsulate business rules as objects that can be combined). Modern PHP favors composition over inheritance and dependency injection over singletons.
Pro Tip
This topic has PHP-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.