Giter VIP home page Giter VIP logo

strategy_design_pattern's Introduction

strategy design pattern GitHub release Maintenance

Travis GitHub Release Date .Net Framework GitHub language count GitHub top language GitHub repo size in bytes

Introduction

A very simple strategy design pattern implementation.

Repository codebase

The repository consists of a project:

  1. Asp.Net Core2 Console

Features

The calculation on 2 numbers can be made through different ways/strategy(s). Basic strategy is defined in an interface

    public interface IStrategy
    {
        int Calculate(int x,int y);
    }
  • Addition calculation implementation
    class Add : IStrategy
    {
        public int Calculate(int x, int y) { return x+y ; }
    }
  • Subtraction calculation implementation
    class Subtract : IStrategy
    {
        public int Calculate(int x, int y) { return x-y ; }
    }
  • Multiplication calculation implementation
    class Multiple : IStrategy
    {
        public int Calculate(int x, int y) { return x*y ; }
    }
  • Division calculation implementation
    class Divide : IStrategy
    {
        public int Calculate(int x, int y) { return x/y ; }
    }
  • Strategy implementation
interface IStrategyCtx
{
	int Perform(StrategyType type, int x, int y);
}
class StrategyCtx : IStrategyCtx
{
  Dictionary<StrategyType, IStrategy> d = new Dictionary<StrategyType, IStrategy>();
  public StrategyCtx()
  {
    d.Add(StrategyType.ADD, new Add());
    d.Add(StrategyType.SUBTRACT, new Subtract());
    d.Add(StrategyType.MULTIPLY, new Multiple());
    d.Add(StrategyType.DIVISION, new Divide());
  }
  public int Perform(StrategyType type, int x, int y)
  {
  	return d[type].Calculate(x, y);
  }
 }  

Support or Contact

Having any trouble? Check out our documentation or contact support and we’ll help you sort it out.

HitCount GitHub contributors license

strategy_design_pattern's People

Contributors

ajeetx avatar

Watchers

James Cloos avatar  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.