What are design patterns in OOP?
Answer
Design patterns are proven, reusable solutions to commonly occurring problems in software design. They are general templates, not specific code — they must be adapted to each situation. Documented by the "Gang of Four" (GoF) in their 1994 book. Three categories: (1) Creational patterns — deal with object creation mechanisms: Singleton: ensure only one instance; Factory Method: define interface for object creation; Abstract Factory: create families of related objects; Builder: construct complex objects step by step; Prototype: copy existing objects; (2) Structural patterns — deal with object composition: Adapter: make incompatible interfaces work together; Decorator: add behavior dynamically; Facade: simplified interface to complex subsystem; Composite: tree structure of objects; Bridge: separate abstraction from implementation; Proxy: placeholder for another object; (3) Behavioral patterns — deal with communication between objects: Observer: notify dependents of state changes; Strategy: define family of algorithms, make them interchangeable; Command: encapsulate request as object; Iterator: traverse collection without exposing structure; Template Method: define algorithm skeleton, let subclasses fill in steps; State: object changes behavior with state; Chain of Responsibility. Why use patterns? Shared vocabulary, proven solutions, faster communication ("use Observer here"), avoid reinventing the wheel, flexible extensible code.