Strategy Design Pattern

Overview: strategy Design pattern is a behavioral design pattern which encapsulate a family of algorithms and select one from the pool for use during runtime. The key idea is to create objects which represent various strategies.

reference : https://blog.bitsrc.io/keep-it-simple-with-the-strategy-design-pattern-c36a14c985e9

Behavioral design pattern is form of design pattern which is concerned about the interactions and behavior of objects. The interaction between the objects should be in such a way that they could easily talk to each other while being loosely coupled.

reference: https://www.javatpoint.com/behavioral-design-pattern

When to use Strategy Design Pattern

  • If you want to choose the algorithm to use at runtime
  • If you notice recurring conditional statement around the related algorithm

How to implement

  1. Identify an algorithm (i.e. a behavior) that the client would prefer to access through a “flex point”.
  2. Specify the signature for that algorithm in an interface.
  3. Bury the alternative implementation details in derived classes.
  4. Clients of the algorithm couple themselves to the interface.

Having the user(user) interact with the interface prevent any changes in derived classes from affecting it.

reference:https://sourcemaking.com/design_patterns/strategy

Leave a comment

Design a site like this with WordPress.com
Get started