Design Patterns

 
 
A design pattern is a recurring solution to a standard problem.

The most well-known design patterns (in total 23) were documented by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides also called The Gang of Four (GOF) in the book Design Patterns -- Elements of Reusable Software (1995).

There a hunderds of design patterns described in the literature. This tutorial only describes the design patterns documented by the GOF.

The GOF has divided the design patterns into three types.

Type name Description
Creational patterns Deal with initializing and configuring classes and objects
  • Abstract Factory
  • Builder Factory
  • Factory Method
  • Prototype Factory
  • Singleton
Structural patterns Deal with decoupling interface and implementation of classes and objects
  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy
Behavioral patterns Deal with dynamic interactions among societies of classes and objects
  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Template
  • Visitor


Creational patterns.



Name Description
Factory Method Method in a derived class creates associates
Abstract Factory Factory for building related objects
Builder Factory for building complex objects incrementally
Prototype Factory for cloning new instances from a prototype
Singleton Factory for a singular (sole) instance






Structural patterns.



Name Description
Adapter Translator adapts a server interface for a client
Bridge Abstraction for binding one of many implementations
Composite Structure for building recursive aggregations
Decorator Decorator extends an object transparently
Facade Facade simplifies the interface for a subsystem
Flyweight Many fine-grained objects shared efficiently
Proxy One object approximates another


Behavioral patterns.



Name Description
Chain of Responsibility Request delegated to the responsible service provider
Command Request as first-class object
Interpreter Language interpreter for a small grammar
Iterator Aggregate elements are accessed sequentially
Mediator Mediator coordinates interactions between its associates
Memento Snapshot captures and restores object states privately
Observer Dependents update automatically when a subject changes
State Object whose behavior depends on its state
Strategy Abstraction for selecting one of many algorithms
Template Method Algorithm with some steps supplied by a derived class
Define the skeleton of an algorithm
Defer some steps to subclasses
Refactor common behavior among subclasses to avoid code duplication
Visitor Operations applied to elements of an heterogeneous object structure


Quick guides







Singleton.



Description
A factory which can only create a single instance of a class.

Usage
to be defined

UML
to be defined

Pattern Implementation

public class Singleton {

    public final static Singleton INSTANCE = new Singleton();

    private Singleton() {
         // prevents creating an instance of this class
    }
}


Examples
to be defined