A design patterns are design patterns that identify common communication patterns between objects and realize these patterns.


$ Iterator - Sequentially access the elements of a collection

Sequentially access the elements of a collection 

Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

Iterator Design Pattern 


$* Observer - Mainly used to implement distributed event handling systems

  • Mainly used to implement distributed event handling systems.

  • A way of notifying change to a number of classes

Background:

In Object Oriented Programming world each and every object is responsible for its own functionalities and sometimes one object needs to depend upon anther object. If we implement logic (tight coupling) in one object (observer) to monitor or track of another object (source) functionality, it will make tight coupling dependency between these 2 objects. If any changes need to be done in source object requires making changes in target object (observer).

Solution:

We should allow loose coupling (no one object depends upon other objects functionality) between the objects. Every object should take care of its functionality and if we need any information from another object it should notify automatically.

Types of a pattern:

  • Subject, Observer Model:

    • A design pattern in which an object called the subject, maintains a list of its dependents called observers and notifies them automatically of any state changes, usually by calling one of their methods.

    • Reference Example 2- Maintain subject Reference

  • Publisher, Subscriber Model:

    • A design pattern in which an object called the publisher, maintains a list of its dependents called subscribers and notifies them automatically of any state changes, usually by calling one of their methods.

    • Reference Example 1 - Using Delegates - Register subscriber 

 


#$* Command - Encapsulate a command request as an object

Encapsulate a command request as an object
  • Encapsulate a request as an object, ‚Äč

    • thereby letting you parameterize clients with different requests, queue or log requests, and

    • support undoable operations.

Command Design Pattern 


Strategy - Encapsulates an algorithm inside a class

Encapsulates an algorithm inside a class
  • Define a family of algorithms, encapsulate each one, and make them interchangeable.

  • Strategy lets the algorithm vary independently from clients that use it.

Strategy Design Pattern 


State - Alter an object's behavior when its state changes

Alter an object's behavior when its state changes

State Design Pattern 


Template Method - Defer the exact steps of an algorithm to a subclass

Defer the exact steps of an algorithm to a subclass
  • Define the skeleton of an algorithm in an operation, deferring some steps to subclasses.

  • Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

Template Method Design Pattern 


# Chain of Responsibility - A way of passing a request between a chain of objects

A way of passing a request between a chain of objects
  • Avoid coupling the sender of a request to its receiver
    • by giving more than one object a chance to handle the request.
  • Chain the receiving objects and pass the request along the chain until an object handles it.

Chain of Responsibility Design Pattern 


Mediator - Defines simplified communication between classes

Defines simplified communication between classes 
  • Define an object that encapsulates how a set of objects interact.

  • Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.

Mediator Desing Pattern 


# Interpreter - A way to include language elements in a program

A way to include language elements in a program

Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

Interpretor Desing Pattern 


Memento - Capture and restore an object's internal state

Capture and restore an object's internal state

Momento Design Pattern 


Visitor - Defines a new operation to a class without change

Defines a new operation to a class without change 
  • Represent an operation to be performed on the elements of an object structure.

  • Visitor lets you define a new operation without changing the classes of the elements on which it operates.

Visitor Design Pattern