I've recently started writing a series of articles on Design Patterns in Java, i.e., Design Patterns explained using Java source code examples. Although it will take me a little while to create each design pattern example, this page will eventually contain links to all of those examples.
If you're not familiar with software design patterns, they're described on Wikipedia like this:
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code.
The usefulness of design patterns is explained well by this quote:
Design patterns can speed up the development process by providing tested, proven development paradigms.
As we all like to program faster -- and we don't like to paint ourselves into corners -- design patterns are a good thing. I've found that design patterns are like being able to talk with an experienced software designer ... a way of capturing "lessons learned" about good software design practices.
Design patterns - history, organization
Design patterns were initially made famous in the "the "Gang of Four" Design Patterns book , and subsequently described in other books, such as The Design Patterns Smalltalk Companion. "Patterns" themselves originated in the field of architecture, as captured and organized by a man named Christopher Alexander (no relation to this author).
Design patterns have been split into at least three categories -- Creational Patterns, Structural Patterns, and Behavioral Patterns -- and in keeping with this organization, my tutorials are organized in the same manner below.
Design patterns in Java
While design patterns are intended to be independent of programming languages, I've found that it's very useful to show examples of design patterns implemented in different languages. For example, if you're not familiar with Smalltalk, the Design Patterns Smalltalk Companion may be a little hard for you to digest, but if you're familiar with a language like Java, a Java design pattern example will be much easier to understand.
Therefore, to specifically try to help Java programmers, I'm creating this series of Java design pattern examples.
Java 'Creational' design pattern examples
According to Wikipedia, "creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation." Here are links to my Java Behavioral Design Pattern examples:
- Factory Method Design Pattern in Java
- Abstract Factory Design Pattern
- Builder Design Pattern
- Object Pool Design Pattern
- Prototype Design Pattern
- Singleton Design Pattern
Java 'Structural' design pattern examples
According to Wikipedia, "structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities." Here are links to my Java Behavioral Design Pattern examples:
- Adapter Design Pattern
- Bridge Design Pattern
- Composite Design Pattern
- Decorator Design Pattern
- Facade Design Pattern
- Flyweight Design Pattern
- Private Class Data
- Proxy Design Pattern
Java 'Behavioral' design pattern examples
According to Wikipedia, "behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication." Here are links to my Java Behavioral Design Pattern examples:
- Chain of Responsibility
- Command Design Pattern in Java
- Interpreter Design Pattern
- Iterator Design Pattern in Java
- Mediator Design Pattern in Java
- Memento Design Pattern
- Null Object Design Pattern
- Observer Design Pattern
- State Design Pattern
- Strategy Design Pattern in Java
- Template Method Design Pattern in Java
- Visitor Design Pattern
While some other "patterns" or "idioms" aren't always considered to be "design patterns", they are nonetheless very helpful. Therefore, I'm including links here to other patterns and idioms that I've written over the years, including The Law of Demeter, and the Model View Controller pattern:
- A Law of Demeter Java example
- A Java Model View Controller (MVC) example
- Model View Controller (MVC) definitions and examples
- A terrific Model View Controller diagram
Java design patterns - Summary
I hope these Java design patterns are helpful. If possible, I'll add more over time.