OOP

Gang of Four Design Patterns

Story Highlights
  • Gang of Four Design Patterns
  • Categories of Design Patterns

Design patterns are solutions to software design problems you find again and again in real-world application development. Patterns are about reusable designs and interactions of objects.

In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns – Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development.

These authors are collectively known as Gang of Four (GOF). According to these authors design patterns are primarily based on the following principles of object orientated design.

>Program to an interface not an implementation
>Favor object composition over inheritance

Purpose
CreationalStructuralBehavioral
ScopeClassFactory MethodAdapter (class)Interpreter
Template Method
ObjectAbstract FactoryAdapter (object)Chain of Responsibility
BuilderBridgeCommand
PrototypeCompositeIterator
SingletonDecoratorMediator
FacadeMemento
FlyweightObserver
ProxyState
Strategy
Visitor
Table: Design Patterns

Design patterns vary in their granularity and level of abstraction. Design patterns can be classified by two criteria (see Table above). That is by Purpose and Scope.

(A) By Purpose means, what a pattern does. Patterns can have either creational, structural or behavioral purpose.

(i) Creational patterns concern the process of object creation (class instantiation).

(ii) Structural patterns deal with the composition of classes or objects.

(iii) Behavioral patterns characterize the ways in which classes or objects interact and distribute responsibility.

(B) Scope specifies whether the pattern applies primarily to classes or to objects.

(i) Class patterns deal with relationships between classes and their sub-classes. These relationships are established through inheritance, so they are static—fixed at compile-time.

(ii) Object patterns deal with object relationships, which can be changed at run-time and are more dynamic.

Creational Design Patterns

Creational design patterns are all about class instantiation. This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.

Factory Method: Creates an instance of several derived classes
Abstract Factory: Creates an instance of several families of classes
Builder: Separates object construction from its representation
Prototype: A fully initialized instance to be copied or cloned
Singleton: A class of which only a single instance can exist

Structural Design Patterns

Structural design patterns are all about Class and Object composition. Structural class-creation patterns use inheritance to compose interfaces. Structural object-patterns define ways to compose objects to obtain new functionality.

Adapter: Match interfaces of different classes
Bridge: Separates an object’s interface from its implementation
Composite: A tree structure of simple and composite objects
Decorator: Add responsibilities to objects dynamically
Facade: A single class that represents an entire subsystem
Flyweight: A fine-grained instance used for efficient sharing
Proxy: An object representing another object

Behavioral Design Patterns

Behavioral design patterns are all about Class’s objects communication. Behavioral patterns are those patterns that are most specifically concerned with communication between objects.

Interpreter: A way to include language elements in a program
Template Method: Defer the exact steps of an algorithm to a subclass
Chain of Responsibility: A way of passing a request between a chain of objects
Command: Encapsulate a command request as an object
Iterator: Sequentially access the elements of a collection
Mediator: Defines simplified communication between classes
Memento: Capture and restore an object’s internal state
Observer: A way of notifying change to a number of classes
State: Alter an object’s behavior when its state changes
Strategy: Encapsulates an algorithm inside a class
Visitor: Defines a new operation to a class without change

Show More

Related Articles

Leave a Reply

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

Check Also
Close
Back to top button
History Of 1st July Get ready for the ICC Men’s Cricket World Cup 2023! Yoga according to the Bhagavad Gita