Foundational Gangs-Of-Four Design Patterns in Java

Hacker News

Foundational (GOF) design patterns

Gang-Of-Four also called as foundation patterns are the 23 basic design patterns that provides solution to common recurring problems in software design. They categorized into three major categories, based on behaviour and characteristics.

  1. Creational patterns
  2. Structural patterns
  3. Behavioral Patterns
  4. Creational patterns

1. Creational design patterns

Creational patterns governs object-creation mechanisms that enable greater levels of reuse in evolving systems.

Abstract FactoryProvides an interface for creating families of related or dependent objects without specifying their concrete classes.
BuilderSeparates the construction of a complex object from its representation so that the same construction process can create different representations.
Factory MethodProvides a way to use an instance as an object factory. The factory can return an instance of one of several possible classes in a class hierarchy, depending on the data provided to it.
PrototypePrototype is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. In a simpler term, using prototype pattern, we will create new instances through cloning existing instances.
SingletonSingleton pattern ensures at most one instance of a particular class is ever created in your application.

2. Structural design patterns

Structural design patterns are design patterns that helps to identify a simple way to realize relationships between entities.

AdapterConvert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.
BridgeDecouple an abstraction from its implementation so that the two can vary independently.
CompositeCompose objects into tree structure to represent part-whole hierarchies.Composite lets client treat individual objects and compositions of objects uniformly.
DecoratorAllows for the dynamic wrapping of objects in order to modify their existing responsibilities and behaviors.
FacadeProvide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.
FlyweightFacilitates the reuse of many fine grained objects, making the utilization of large numbers of objects more efficient.
ProxyAllows for object level access control by acting as a pass through entity or a placeholder object.

3. Behavioral design patterns

Behavioral design patterns identifies the common communication patterns between objects.

Chain of ResponsibilityGives more than one object an opportunity to handle a request by linking receiving objects together.
CommandEncapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
InterpreterGiven a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
IteratorProvides a way to access the elements of an aggregate object without exposing its underlying representation.
MediatorAllows loose coupling by encapsulating the way disparate sets of objects interact and communicate with each other. Allows for the actions of each object set to vary independently of one another.
MementoCaptures and externalizes an object’s internal state so that it can be restored later, all without violating encapsulation.
ObserverObserver design pattern defines one-to-many dependency between objects in which one object changes state, all its dependents are notified.
StateAllows an object to alter its behavior when its internal state changes. The object will appear to change its class.
StrategyDefines a set of encapsulated algorithms that can be swapped to carry out a specific behavior.
Template MethodDefines the steps for an algorithm and allows subclass to provide implementation for one or more steps.
VisitorAllows for one or more operation to be applied to a set of objects at runtime, decoupling the operations from the object structure.


A blogger, a bit of tech freak and a software developer. He is a thought leader in the fusion of design and mobile technologies. He is the author of Xamarin Mobile Application Development for Android Book (, DZone MVB and founder of

Related Articles

Join The Discussion

Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.