How do the SOLID principles relate to GoF patterns?
Answer
GoF patterns and SOLID principles are deeply intertwined — patterns are often concrete implementations of SOLID principles. SRP (Single Responsibility): Command encapsulates one operation; Facade groups related operations behind one interface. OCP (Open/Closed): Strategy, State, and Decorator allow behavior extension without modifying existing classes — adding a new strategy or decorator doesn't touch existing code. LSP (Liskov Substitution): all GoF patterns that use polymorphism rely on this — a concrete strategy must be substitutable for the abstract strategy. ISP (Interface Segregation): patterns like Iterator and Observer define lean, focused interfaces. DIP (Dependency Inversion): Factory Method, Abstract Factory, and Builder all invert the dependency on concrete classes — clients depend on abstractions, not on concrete implementations. Patterns are the "how"; SOLID principles are the "why."
Previous
How do you implement a thread-safe Singleton using double-checked locking?
Next
What is the difference between GoF anti-patterns and the patterns themselves?
More Design Patterns (Gang of Four) Questions
View all →- Advanced How do you implement a thread-safe Singleton using double-checked locking?
- Advanced What is the difference between GoF anti-patterns and the patterns themselves?
- Advanced How are GoF patterns used in modern frameworks like Spring and Django?
- Advanced What criteria should guide pattern selection?
- Advanced How do GoF patterns apply in functional programming?