Git Product home page Git Product logo

spring-strategy-designpatterns's Introduction

Strategy Design Pattern

What does Strategy mean ? “a plan of action designed to achieve a long-term or overall aim.”

Lets think in terms of Software design !! STRATEGIES = DIFFERENT ALGORITHMS

Questions to consider before thinking about this pattern

How often do you feel the need to select an algorithm at run time? Do you have a set of algorithms that are selected based on certain run time changes / configs ? Is your code Open for Extension ?

If the answer is yes for any of the above questions , Strategy Pattern might be a good option for you.

Definition : The strategy pattern is a behavioral pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly , we can pass the algorithm at run time from a family of algorithms.

For Instance , a application that uses REST to call apis might need to choose from different REST Templates(Ex: Proxy Enabled, SSL Configured) based on the build env( dev, test , prod). This might not be known until run time . 

Strategy design pattern lets you choose the correct Rest Template based on the env during run time without any changes in the code. Other classic example is when you have set of validation algorithms that needs to be selected based on inputs.

Strategy uses Composition instead of Inheritance.It is also compatible with OCP , which states that class should be open for extension but closed for modification.

spring-strategy-designpatterns's People

Contributors

himsmittal avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.