GoF Design Patterns Overview

Connect with

GoF Design Patterns OverviewThere are three types of GoF Design patterns: Creational Design Pattern, Structural Design Pattern and Behavioral Design Pattern. GoF: gang of four desgin pattern.

1. Overview of GoF Design Patterns

  1. Creational Design Pattern : used for creating object in software design pattern.
  2. Structural Design Pattern : refer for structuring of object(s) in software design pattern.
  3. Behavioral Design Pattern : used for behavior of objects in software design pattern.

2. GoF: Creational Design Pattern

Creational design pattern is one of the GoF desing patterns. You will learn more about creational pattern. Key points are as:

  1. Deal with one of the most commonly performed tasks in an OO application, the creation of objects.
  2. Support a uniform, simple, and controlled mechanism to create objects.
  3. Allow the encapsulation of the details about what classes are instantiated and how these instances are created.
  4. Encourage the use of interfaces, which reduces coupling.

3. Type of Creational Design Patterns

  1. Singleton: Provides a controlled object creation mechanism to ensure that only one instance of a given class exists.
  2. Prototype: Provides a simpler way of creating an object by cloning it from an existing (prototype) object.
  3. Factory Method: Subclass decides which concrete class to instantiate. When a client object does not know which class to instantiate , it can make use of the factory method to create an instance of an appropriate class from a class hierarchy or a family of related classes.
  4. Abstract Factory: Allows the creation of an instance of a class from a suite of related classes without having a client object to specify the actual concrete class to be instantiated.
  5. Builder: Allows creation of a complex object by providing the information on only its type and content, keeping the details of the object creation transparent to the client. This allows the same construction process to produce different representations of the object.

4. Structural Design Pattern

Structural design patterns is one of the GoF design patterns. Following are the structural design pattern with high level one liner things about this.

  • Adapter : adapt the object behaviors
  • Bridge:
  • Composite: allows you to compose object into tree structures to represent part-whole hierarchies. client treats composite object and individual object uniformly.
  • Decorator:
  • Facade: Make interface simpler
  • Flyweight: make object light weight by reducing
  • Proxy: hiding implantation from client

5. Behavioral Design Patterns

  • Chain Of Responsibility:
  • Command:
  • Proxy: provides a surrogate or placeholder for another object to control access to it.
  • Interpreter:
  • Iterator: Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
  • Mediator:
  • Memento:
  • Observer:
  • State:
  • Strategy: Encapsulate interchangeable behaviors and use delegation to decide which behavior to use.
  • Template Method: Subclass decides how to implement step in an algorithm.

6. Patterns in Java Collection

Collectional pattern primarily deal with group or collections of Object. It allow the definition of operations on collections of objects, which are follows:

  • Composite:
  • Iterator:
  • Flyweight:
  • Visitor:

7. One liner about Adaptor Decorator and Facade

  • Adapter : Convert one interface to another
  • Decorator: Does not alter the interface but add responsibility.
  • Facade : Make an interface simpler

8. Strategy Vs Template Method

Template Method job is to define the outline of an algorithm, but subclass do some of the work. It means , I ( Template) have more control over my algorithm and I don’t duplicate code. All the duplicate code put into super class so that all subclass share those code.
Strategy method use object composition while Template use inheritance. Click here Template Method Vs Strategy Design pattern

9. Who wraps object for what?

  • Adapter: Wraps another object and provides a different interface to it.
  • Decorator: wraps another object and provides additional behavior for it.
  • Facade: wraps a bunch of objects to simplify their interface.
  • Proxy: wraps another object to control access to it.

I hope you enjoyed this post of behavioral design patterns, and you can visit design patterns tutorial for more details
Visit Wiki page.
Happy learning of GoF design Patterns:)

Connect with

Leave a Comment

Your email address will not be published. Required fields are marked *