Sunday 8 August 2021

Strategy Pattern

Strategy pattern comes under behavioral design patterns category, this pattern defines skeleton of an algorithm in the superclass but lets subclasses override specific steps of algorithm without changing its structures. This pattern also known as policy pattern.

Strategy Pattern Characteristics.

 

 

 

 

 

 

 

 

Context

Has a reference to a strategy and invoke it

 

IStrategy

Defines the interface for the given strategy

 

Strategy

A concrete implementation of the strategy

 

 

 

 

 

 

 

 


Strategy Pattern Advantages.

  1. A more extensible, object oriented and dynamic implementation.
  2. Easily add new strategies without affecting existing ones.
  3. Clean approach with single responsibility in mind.

Strategy Pattern Disadvantage.

  1. Make sure you don't make your applications more complex than then they have to be!

Strategy Pattern Example.

Shipping of e-commerce product via various courier service provider, where we can implement strategy pattern well. Shipping of product via postal service, FedEx, DTDC, Bluedart, Delhivery. Where shipping strategy is abstract or super class and Postal Service, FedEx, DTDC, BlueDart, Delhivery are sub class and has its own implementation. 

No comments:

Post a Comment

Custome Service Class to connect wcf service

  using  System; using  System.ServiceModel; namespace Custom.Service.Client {      // Borrowed from: http://old.iserviceoriented.com/blog/p...