Middle
What is GOF (Gang of Four) and which patterns from this book are implemented in the standard JDK?
sobes.tech AI
Answer from AI
GOF (Gang of Four) is a group of four authors: Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, who in 1994 wrote the book "Design Patterns: Elements of Reusable Object-Oriented Software." It describes 23 classic design patterns, divided into three categories: creational, structural, and behavioral.
Several patterns from this book are implemented in the standard JDK, for example:
- Singleton — a pattern that guarantees a single instance of a class. For example, the
Runtimeclass. - Factory Method — a pattern for creating objects through a factory method. For example,
Calendar.getInstance(). - Observer — a pattern for subscribing to events. For example,
java.util.ObserverandObservable(although deprecated). - Decorator — dynamically extending functionality. For example,
java.io.BufferedInputStreamwrapsInputStream. - Adapter — adapting interfaces. For example,
java.util.Arrays#asList()returns an adapter of an array to a list.
These patterns are widely used in the JDK to increase flexibility and reusability of code.