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."