It is not ready-made code, but a template or best practice to solve recurring design problems.
In simple words:
A design pattern tells how to structure classes and objects to solve a problem in a clean and maintainable way.
Types of Design Patterns (GoF – Gang of Four)
Design patterns are mainly divided into 3 categories:
1) Creational Patterns
Used to create objects in a proper and flexible way.
Singleton – Only one instance of a class is created.
Factory Method – Creates objects without specifying exact class.
Abstract Factory – Creates families of related objects.
Builder – Builds complex objects step by step.
Prototype – Creates new objects by copying existing object.
2) Structural Patterns
Used to organize classes and objects into larger structures.
Adapter – Converts one interface into another.
Bridge – Separates abstraction from implementation.
Composite – Treats individual objects and groups uniformly.
Decorator – Adds new behavior to objects dynamically.
Facade – Provides simple interface to complex system.
Flyweight – Reduces memory usage by sharing objects.
Proxy – Controls access to another object.
3) Behavioral Patterns
Used to manage communication between objects.
Observer – Notifies multiple objects when state changes.
Strategy – Defines family of algorithms and makes them interchangeable.
Command – Encapsulates a request as an object.
Chain of Responsibility – Passes request along a chain of handlers.
Mediator – Controls communication between objects.
State – Changes behavior based on internal state.
Template Method – Defines skeleton of algorithm.
Iterator – Access elements sequentially.
Memento – Saves and restores object state.
Visitor – Adds new operation without changing classes.
Interpreter – Defines grammar for a language.