Design patterns
Master the GoF patterns with real-world examples and code
Master the most frequently asked design pattern interview questions covering creational patterns like Singleton and Factory, structural patterns like Adapter and Decorator, and behavioral patterns like Observer and Strategy. Each pattern includes intent, structure, real-world use cases, and Java implementation.
Creational patterns 16 patterns
Singleton
Ensure a class has only one instance and provide a global access point to it.
Factory Method
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Abstract Factory
Provide an interface for creating families of related objects without specifying their concrete classes.
Builder
Separate the construction of a complex object from its representation so the same process can create different representations.
Prototype
Create new objects by copying (cloning) an existing object.
Adapter
Convert the interface of a class into another interface that clients expect.
Decorator
Attach additional responsibilities to an object dynamically. A flexible alternative to subclassing.
Facade
Provide a simplified, unified interface to a complex subsystem.
Proxy
Provide a surrogate or placeholder for another object to control access to it.
Composite
Compose objects into tree structures to represent part-whole hierarchies. Treat individual and composite objects uniformly.
Template Method
Define the skeleton of an algorithm in a base class, deferring specific steps to subclasses.
Observer
Define a one-to-many dependency so dependents are notified automatically when state changes.
Strategy
Define a family of algorithms, encapsulate each one, and make them interchangeable.
Command
Encapsulate a request as an object for queuing, logging, and undoable operations.
Chain of Responsibility
Pass a request along a chain of handlers. Each decides to process or pass to the next.
State
Allow an object to alter its behavior when its internal state changes.