design-patterns
12 tutorials tagged “design-patterns”.
- The Decorator Pattern in Java I/Ojava.io adds features by wrapping streams inside other streams. Learn how the decorator pattern works there and how to write your own filter stream.
- Dynamic Proxies in JavaA dynamic proxy is an object created at run time that implements interfaces and sends every call to one InvocationHandler. Learn how Spring-style wrappers work.
- Thread-Safe Singleton in JavaMake a singleton safe for many threads: synchronized getInstance, double-checked locking with volatile, the holder idiom and the enum singleton, compared.
- Behavioral Design PatternsThe eleven patterns for how objects share work, from Chain of Responsibility to Visitor, each explained with an everyday comparison and a runnable example.
- Builder Pattern in JavaCreate objects with many optional settings readably: the telescoping-constructor problem, a fluent static nested Builder, validation in build(), and records.
- Creational Design PatternsThe five patterns for making objects: Singleton, Factory Method, Abstract Factory, Builder and Prototype, each explained simply with a runnable example.
- Design Patterns in JavaAll 23 classic design patterns in plain English: what each one is for, an everyday comparison, and where Java itself uses it.
- Factory Pattern in JavaLet one place decide which class to create: static factory methods, a factory for discount policies by customer type, and factories in the JDK.
- Observer Pattern in JavaNotify many objects when one object changes: subjects and observers, subscribing and unsubscribing, an order-status example, and its pitfalls.
- Singleton Pattern in JavaGuarantee exactly one instance of a class: eager, lazy, holder and enum singletons, their thread-safety, how reflection breaks them, and when to avoid them.