Apply discount changes with Strategy pattern

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
2












I am implementing strategy pattern. I have defined a strategy as interfaces and concrete classes to implement the strategy. Based on user selection/configuration, the algorithm to apply the discount changes.



 public interface IStrategy

double calculate(double x, double y);



concrete classes implementing the gold strategy is listed below -



public class clsGoldDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.8;


}


concrete classes implementing the platinumstrategy is listed below -



public class clsPlatinumDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.7;




The business logic to apply



public class clsBL

public double costPrice get; set;
public double qty get; set;
IStrategy _strategy;

public clsBL(IStrategy strategy)

_strategy = strategy;


public double GetfinalPrice(double cp, double qty)

return _strategy.calculate(cp, qty);





//Main method



static void Main(string args)

Console.WriteLine("Enter the discount Plan (Gold/Platinum)");
string filter = Console.ReadLine().ToUpper();
double result = 0;

if (filter.Length > 0)

switch (filter)

case "GOLD":
//Gold
clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
blgold.costPrice = 5;
blgold.qty = 10;

result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
break;

case "PLATINUM":
//Platinum
clsBL blplatinum = new clsBL(new clsPlatinumDiscountStrategy());
blplatinum.costPrice = 10;
blplatinum.qty = 8;

result = blplatinum.GetfinalPrice(blplatinum.costPrice, blplatinum.qty);
break;
default:
Console.WriteLine("Enter the discount value as either gold or platinum");
break;


Console.WriteLine("The result for " + filter + " is " + result);


else

Console.WriteLine("Enter the discount value");
return;



Console.ReadLine();











share|improve this question















migrated from stackoverflow.com Oct 1 at 10:00


This question came from our site for professional and enthusiast programmers.










  • 1




    I have rolled back your last edit. Please see What should I do when someone answers my question?: Do not change the code in the question after receiving an answer. Incorporating advice from an answer into the question violates the question-and-answer nature of this site.
    – t3chb0t
    Oct 3 at 5:40










  • sure. I will keep this in mind in future course of actions
    – krishna_v
    Oct 3 at 5:41














up vote
5
down vote

favorite
2












I am implementing strategy pattern. I have defined a strategy as interfaces and concrete classes to implement the strategy. Based on user selection/configuration, the algorithm to apply the discount changes.



 public interface IStrategy

double calculate(double x, double y);



concrete classes implementing the gold strategy is listed below -



public class clsGoldDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.8;


}


concrete classes implementing the platinumstrategy is listed below -



public class clsPlatinumDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.7;




The business logic to apply



public class clsBL

public double costPrice get; set;
public double qty get; set;
IStrategy _strategy;

public clsBL(IStrategy strategy)

_strategy = strategy;


public double GetfinalPrice(double cp, double qty)

return _strategy.calculate(cp, qty);





//Main method



static void Main(string args)

Console.WriteLine("Enter the discount Plan (Gold/Platinum)");
string filter = Console.ReadLine().ToUpper();
double result = 0;

if (filter.Length > 0)

switch (filter)

case "GOLD":
//Gold
clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
blgold.costPrice = 5;
blgold.qty = 10;

result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
break;

case "PLATINUM":
//Platinum
clsBL blplatinum = new clsBL(new clsPlatinumDiscountStrategy());
blplatinum.costPrice = 10;
blplatinum.qty = 8;

result = blplatinum.GetfinalPrice(blplatinum.costPrice, blplatinum.qty);
break;
default:
Console.WriteLine("Enter the discount value as either gold or platinum");
break;


Console.WriteLine("The result for " + filter + " is " + result);


else

Console.WriteLine("Enter the discount value");
return;



Console.ReadLine();











share|improve this question















migrated from stackoverflow.com Oct 1 at 10:00


This question came from our site for professional and enthusiast programmers.










  • 1




    I have rolled back your last edit. Please see What should I do when someone answers my question?: Do not change the code in the question after receiving an answer. Incorporating advice from an answer into the question violates the question-and-answer nature of this site.
    – t3chb0t
    Oct 3 at 5:40










  • sure. I will keep this in mind in future course of actions
    – krishna_v
    Oct 3 at 5:41












up vote
5
down vote

favorite
2









up vote
5
down vote

favorite
2






2





I am implementing strategy pattern. I have defined a strategy as interfaces and concrete classes to implement the strategy. Based on user selection/configuration, the algorithm to apply the discount changes.



 public interface IStrategy

double calculate(double x, double y);



concrete classes implementing the gold strategy is listed below -



public class clsGoldDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.8;


}


concrete classes implementing the platinumstrategy is listed below -



public class clsPlatinumDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.7;




The business logic to apply



public class clsBL

public double costPrice get; set;
public double qty get; set;
IStrategy _strategy;

public clsBL(IStrategy strategy)

_strategy = strategy;


public double GetfinalPrice(double cp, double qty)

return _strategy.calculate(cp, qty);





//Main method



static void Main(string args)

Console.WriteLine("Enter the discount Plan (Gold/Platinum)");
string filter = Console.ReadLine().ToUpper();
double result = 0;

if (filter.Length > 0)

switch (filter)

case "GOLD":
//Gold
clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
blgold.costPrice = 5;
blgold.qty = 10;

result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
break;

case "PLATINUM":
//Platinum
clsBL blplatinum = new clsBL(new clsPlatinumDiscountStrategy());
blplatinum.costPrice = 10;
blplatinum.qty = 8;

result = blplatinum.GetfinalPrice(blplatinum.costPrice, blplatinum.qty);
break;
default:
Console.WriteLine("Enter the discount value as either gold or platinum");
break;


Console.WriteLine("The result for " + filter + " is " + result);


else

Console.WriteLine("Enter the discount value");
return;



Console.ReadLine();











share|improve this question















I am implementing strategy pattern. I have defined a strategy as interfaces and concrete classes to implement the strategy. Based on user selection/configuration, the algorithm to apply the discount changes.



 public interface IStrategy

double calculate(double x, double y);



concrete classes implementing the gold strategy is listed below -



public class clsGoldDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.8;


}


concrete classes implementing the platinumstrategy is listed below -



public class clsPlatinumDiscountStrategy : IStrategy

public double calculate(double x, double y)

return (x * y) * 0.7;




The business logic to apply



public class clsBL

public double costPrice get; set;
public double qty get; set;
IStrategy _strategy;

public clsBL(IStrategy strategy)

_strategy = strategy;


public double GetfinalPrice(double cp, double qty)

return _strategy.calculate(cp, qty);





//Main method



static void Main(string args)

Console.WriteLine("Enter the discount Plan (Gold/Platinum)");
string filter = Console.ReadLine().ToUpper();
double result = 0;

if (filter.Length > 0)

switch (filter)

case "GOLD":
//Gold
clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
blgold.costPrice = 5;
blgold.qty = 10;

result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
break;

case "PLATINUM":
//Platinum
clsBL blplatinum = new clsBL(new clsPlatinumDiscountStrategy());
blplatinum.costPrice = 10;
blplatinum.qty = 8;

result = blplatinum.GetfinalPrice(blplatinum.costPrice, blplatinum.qty);
break;
default:
Console.WriteLine("Enter the discount value as either gold or platinum");
break;


Console.WriteLine("The result for " + filter + " is " + result);


else

Console.WriteLine("Enter the discount value");
return;



Console.ReadLine();








c# design-patterns






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 3 at 5:40









t3chb0t

32.4k64399




32.4k64399










asked Oct 1 at 6:29









krishna_v

1273




1273




migrated from stackoverflow.com Oct 1 at 10:00


This question came from our site for professional and enthusiast programmers.






migrated from stackoverflow.com Oct 1 at 10:00


This question came from our site for professional and enthusiast programmers.









  • 1




    I have rolled back your last edit. Please see What should I do when someone answers my question?: Do not change the code in the question after receiving an answer. Incorporating advice from an answer into the question violates the question-and-answer nature of this site.
    – t3chb0t
    Oct 3 at 5:40










  • sure. I will keep this in mind in future course of actions
    – krishna_v
    Oct 3 at 5:41












  • 1




    I have rolled back your last edit. Please see What should I do when someone answers my question?: Do not change the code in the question after receiving an answer. Incorporating advice from an answer into the question violates the question-and-answer nature of this site.
    – t3chb0t
    Oct 3 at 5:40










  • sure. I will keep this in mind in future course of actions
    – krishna_v
    Oct 3 at 5:41







1




1




I have rolled back your last edit. Please see What should I do when someone answers my question?: Do not change the code in the question after receiving an answer. Incorporating advice from an answer into the question violates the question-and-answer nature of this site.
– t3chb0t
Oct 3 at 5:40




I have rolled back your last edit. Please see What should I do when someone answers my question?: Do not change the code in the question after receiving an answer. Incorporating advice from an answer into the question violates the question-and-answer nature of this site.
– t3chb0t
Oct 3 at 5:40












sure. I will keep this in mind in future course of actions
– krishna_v
Oct 3 at 5:41




sure. I will keep this in mind in future course of actions
– krishna_v
Oct 3 at 5:41










3 Answers
3






active

oldest

votes

















up vote
5
down vote













The classes seem OK but the usage makes no sense:



 case "GOLD":
//Gold
clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
blgold.costPrice = 5;
blgold.qty = 10;

result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
break;


This code (and the other switch case) does not use the polymorphism that the interface IStrategy enables. Rather, you can have simply written this code as:



 case "GOLD":
double GetGoldPrice(double x, double y) => (x * y) * 0.8;
result = GetGoldPrice(5, 10);
break;


Here, all classes and interfaces are deleted. There is just a static method.



If you want to use the strategy pattern it must look something like:



IStrategy strategy = GetStrategy();
strategy.Calculate(...);


Here, GetStrategy() can return any object compliant with that interface and further code does depend on any concrete type.




Regarding naming, the classes do not have to be called "Strategy". I'd use the names IDiscountCalculator and GoldDicountCalculator. Or, instead of "Calculator" you could use "Model" or "Provider".






share|improve this answer






















  • how do we pass the parameters in this?(for cost price and qty). you mean to say we do not add dependency injection to the clBL class. could you kindly detail me
    – krishna_v
    Oct 1 at 10:35











  • I depends on the way you want the parameters to behave. Maybe you should give the parameters to the strategy constructor. Then, the parameters are fixed for the lifetime of the strategy object. If the parameters are dynamic, then they should be parameters to the Calculate method. They should not be fields of settable properties on IStrategy.
    – usr
    Oct 1 at 10:56










  • Well, they could be settable if you want a strategy to be changeable. Nothing wrong with that in principle... But immutable objects usually make for a cleaner API.
    – usr
    Oct 1 at 10:58










  • @krishna_v there’s no sense in injecting dependencies you’re not using. As far as I can tell, you have properties that aren’t being used.
    – RubberDuck
    2 days ago

















up vote
5
down vote













x and y are really bad parameter names. I had to look at the client code to figure out that these were actually cost and quantity.






share|improve this answer



























    up vote
    2
    down vote














    public double costPrice get; set; 
    public double qty get; set;



    There is no point of having these two properties if you are passing those values to GetfinalPrice anyway:




    public double GetfinalPrice(double cp, double qty)

    return _strategy.calculate(cp, qty);




    Pick one, otherwise it's pretty confusing.






    share|improve this answer




















    • I have modified the code. Now i am not sure how to pass the params to the gold and platinum strategy? I have hard coded the values.
      – krishna_v
      Oct 3 at 5:35










    • @krishna_v I have modified the code. - this is not good because you must not change it after receiving answers... you need to undo the edit... or someone else will do it :-]
      – t3chb0t
      Oct 3 at 5:37











    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "196"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f204676%2fapply-discount-changes-with-strategy-pattern%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    The classes seem OK but the usage makes no sense:



     case "GOLD":
    //Gold
    clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
    blgold.costPrice = 5;
    blgold.qty = 10;

    result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
    break;


    This code (and the other switch case) does not use the polymorphism that the interface IStrategy enables. Rather, you can have simply written this code as:



     case "GOLD":
    double GetGoldPrice(double x, double y) => (x * y) * 0.8;
    result = GetGoldPrice(5, 10);
    break;


    Here, all classes and interfaces are deleted. There is just a static method.



    If you want to use the strategy pattern it must look something like:



    IStrategy strategy = GetStrategy();
    strategy.Calculate(...);


    Here, GetStrategy() can return any object compliant with that interface and further code does depend on any concrete type.




    Regarding naming, the classes do not have to be called "Strategy". I'd use the names IDiscountCalculator and GoldDicountCalculator. Or, instead of "Calculator" you could use "Model" or "Provider".






    share|improve this answer






















    • how do we pass the parameters in this?(for cost price and qty). you mean to say we do not add dependency injection to the clBL class. could you kindly detail me
      – krishna_v
      Oct 1 at 10:35











    • I depends on the way you want the parameters to behave. Maybe you should give the parameters to the strategy constructor. Then, the parameters are fixed for the lifetime of the strategy object. If the parameters are dynamic, then they should be parameters to the Calculate method. They should not be fields of settable properties on IStrategy.
      – usr
      Oct 1 at 10:56










    • Well, they could be settable if you want a strategy to be changeable. Nothing wrong with that in principle... But immutable objects usually make for a cleaner API.
      – usr
      Oct 1 at 10:58










    • @krishna_v there’s no sense in injecting dependencies you’re not using. As far as I can tell, you have properties that aren’t being used.
      – RubberDuck
      2 days ago














    up vote
    5
    down vote













    The classes seem OK but the usage makes no sense:



     case "GOLD":
    //Gold
    clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
    blgold.costPrice = 5;
    blgold.qty = 10;

    result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
    break;


    This code (and the other switch case) does not use the polymorphism that the interface IStrategy enables. Rather, you can have simply written this code as:



     case "GOLD":
    double GetGoldPrice(double x, double y) => (x * y) * 0.8;
    result = GetGoldPrice(5, 10);
    break;


    Here, all classes and interfaces are deleted. There is just a static method.



    If you want to use the strategy pattern it must look something like:



    IStrategy strategy = GetStrategy();
    strategy.Calculate(...);


    Here, GetStrategy() can return any object compliant with that interface and further code does depend on any concrete type.




    Regarding naming, the classes do not have to be called "Strategy". I'd use the names IDiscountCalculator and GoldDicountCalculator. Or, instead of "Calculator" you could use "Model" or "Provider".






    share|improve this answer






















    • how do we pass the parameters in this?(for cost price and qty). you mean to say we do not add dependency injection to the clBL class. could you kindly detail me
      – krishna_v
      Oct 1 at 10:35











    • I depends on the way you want the parameters to behave. Maybe you should give the parameters to the strategy constructor. Then, the parameters are fixed for the lifetime of the strategy object. If the parameters are dynamic, then they should be parameters to the Calculate method. They should not be fields of settable properties on IStrategy.
      – usr
      Oct 1 at 10:56










    • Well, they could be settable if you want a strategy to be changeable. Nothing wrong with that in principle... But immutable objects usually make for a cleaner API.
      – usr
      Oct 1 at 10:58










    • @krishna_v there’s no sense in injecting dependencies you’re not using. As far as I can tell, you have properties that aren’t being used.
      – RubberDuck
      2 days ago












    up vote
    5
    down vote










    up vote
    5
    down vote









    The classes seem OK but the usage makes no sense:



     case "GOLD":
    //Gold
    clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
    blgold.costPrice = 5;
    blgold.qty = 10;

    result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
    break;


    This code (and the other switch case) does not use the polymorphism that the interface IStrategy enables. Rather, you can have simply written this code as:



     case "GOLD":
    double GetGoldPrice(double x, double y) => (x * y) * 0.8;
    result = GetGoldPrice(5, 10);
    break;


    Here, all classes and interfaces are deleted. There is just a static method.



    If you want to use the strategy pattern it must look something like:



    IStrategy strategy = GetStrategy();
    strategy.Calculate(...);


    Here, GetStrategy() can return any object compliant with that interface and further code does depend on any concrete type.




    Regarding naming, the classes do not have to be called "Strategy". I'd use the names IDiscountCalculator and GoldDicountCalculator. Or, instead of "Calculator" you could use "Model" or "Provider".






    share|improve this answer














    The classes seem OK but the usage makes no sense:



     case "GOLD":
    //Gold
    clsBL blgold = new clsBL(new clsGoldDiscountStrategy());
    blgold.costPrice = 5;
    blgold.qty = 10;

    result = blgold.GetfinalPrice(blgold.costPrice, blgold.qty);
    break;


    This code (and the other switch case) does not use the polymorphism that the interface IStrategy enables. Rather, you can have simply written this code as:



     case "GOLD":
    double GetGoldPrice(double x, double y) => (x * y) * 0.8;
    result = GetGoldPrice(5, 10);
    break;


    Here, all classes and interfaces are deleted. There is just a static method.



    If you want to use the strategy pattern it must look something like:



    IStrategy strategy = GetStrategy();
    strategy.Calculate(...);


    Here, GetStrategy() can return any object compliant with that interface and further code does depend on any concrete type.




    Regarding naming, the classes do not have to be called "Strategy". I'd use the names IDiscountCalculator and GoldDicountCalculator. Or, instead of "Calculator" you could use "Model" or "Provider".







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 1 at 10:10

























    answered Oct 1 at 9:11









    usr

    665310




    665310











    • how do we pass the parameters in this?(for cost price and qty). you mean to say we do not add dependency injection to the clBL class. could you kindly detail me
      – krishna_v
      Oct 1 at 10:35











    • I depends on the way you want the parameters to behave. Maybe you should give the parameters to the strategy constructor. Then, the parameters are fixed for the lifetime of the strategy object. If the parameters are dynamic, then they should be parameters to the Calculate method. They should not be fields of settable properties on IStrategy.
      – usr
      Oct 1 at 10:56










    • Well, they could be settable if you want a strategy to be changeable. Nothing wrong with that in principle... But immutable objects usually make for a cleaner API.
      – usr
      Oct 1 at 10:58










    • @krishna_v there’s no sense in injecting dependencies you’re not using. As far as I can tell, you have properties that aren’t being used.
      – RubberDuck
      2 days ago
















    • how do we pass the parameters in this?(for cost price and qty). you mean to say we do not add dependency injection to the clBL class. could you kindly detail me
      – krishna_v
      Oct 1 at 10:35











    • I depends on the way you want the parameters to behave. Maybe you should give the parameters to the strategy constructor. Then, the parameters are fixed for the lifetime of the strategy object. If the parameters are dynamic, then they should be parameters to the Calculate method. They should not be fields of settable properties on IStrategy.
      – usr
      Oct 1 at 10:56










    • Well, they could be settable if you want a strategy to be changeable. Nothing wrong with that in principle... But immutable objects usually make for a cleaner API.
      – usr
      Oct 1 at 10:58










    • @krishna_v there’s no sense in injecting dependencies you’re not using. As far as I can tell, you have properties that aren’t being used.
      – RubberDuck
      2 days ago















    how do we pass the parameters in this?(for cost price and qty). you mean to say we do not add dependency injection to the clBL class. could you kindly detail me
    – krishna_v
    Oct 1 at 10:35





    how do we pass the parameters in this?(for cost price and qty). you mean to say we do not add dependency injection to the clBL class. could you kindly detail me
    – krishna_v
    Oct 1 at 10:35













    I depends on the way you want the parameters to behave. Maybe you should give the parameters to the strategy constructor. Then, the parameters are fixed for the lifetime of the strategy object. If the parameters are dynamic, then they should be parameters to the Calculate method. They should not be fields of settable properties on IStrategy.
    – usr
    Oct 1 at 10:56




    I depends on the way you want the parameters to behave. Maybe you should give the parameters to the strategy constructor. Then, the parameters are fixed for the lifetime of the strategy object. If the parameters are dynamic, then they should be parameters to the Calculate method. They should not be fields of settable properties on IStrategy.
    – usr
    Oct 1 at 10:56












    Well, they could be settable if you want a strategy to be changeable. Nothing wrong with that in principle... But immutable objects usually make for a cleaner API.
    – usr
    Oct 1 at 10:58




    Well, they could be settable if you want a strategy to be changeable. Nothing wrong with that in principle... But immutable objects usually make for a cleaner API.
    – usr
    Oct 1 at 10:58












    @krishna_v there’s no sense in injecting dependencies you’re not using. As far as I can tell, you have properties that aren’t being used.
    – RubberDuck
    2 days ago




    @krishna_v there’s no sense in injecting dependencies you’re not using. As far as I can tell, you have properties that aren’t being used.
    – RubberDuck
    2 days ago












    up vote
    5
    down vote













    x and y are really bad parameter names. I had to look at the client code to figure out that these were actually cost and quantity.






    share|improve this answer
























      up vote
      5
      down vote













      x and y are really bad parameter names. I had to look at the client code to figure out that these were actually cost and quantity.






      share|improve this answer






















        up vote
        5
        down vote










        up vote
        5
        down vote









        x and y are really bad parameter names. I had to look at the client code to figure out that these were actually cost and quantity.






        share|improve this answer












        x and y are really bad parameter names. I had to look at the client code to figure out that these were actually cost and quantity.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 1 at 13:29









        RubberDuck

        27k454156




        27k454156




















            up vote
            2
            down vote














            public double costPrice get; set; 
            public double qty get; set;



            There is no point of having these two properties if you are passing those values to GetfinalPrice anyway:




            public double GetfinalPrice(double cp, double qty)

            return _strategy.calculate(cp, qty);




            Pick one, otherwise it's pretty confusing.






            share|improve this answer




















            • I have modified the code. Now i am not sure how to pass the params to the gold and platinum strategy? I have hard coded the values.
              – krishna_v
              Oct 3 at 5:35










            • @krishna_v I have modified the code. - this is not good because you must not change it after receiving answers... you need to undo the edit... or someone else will do it :-]
              – t3chb0t
              Oct 3 at 5:37















            up vote
            2
            down vote














            public double costPrice get; set; 
            public double qty get; set;



            There is no point of having these two properties if you are passing those values to GetfinalPrice anyway:




            public double GetfinalPrice(double cp, double qty)

            return _strategy.calculate(cp, qty);




            Pick one, otherwise it's pretty confusing.






            share|improve this answer




















            • I have modified the code. Now i am not sure how to pass the params to the gold and platinum strategy? I have hard coded the values.
              – krishna_v
              Oct 3 at 5:35










            • @krishna_v I have modified the code. - this is not good because you must not change it after receiving answers... you need to undo the edit... or someone else will do it :-]
              – t3chb0t
              Oct 3 at 5:37













            up vote
            2
            down vote










            up vote
            2
            down vote










            public double costPrice get; set; 
            public double qty get; set;



            There is no point of having these two properties if you are passing those values to GetfinalPrice anyway:




            public double GetfinalPrice(double cp, double qty)

            return _strategy.calculate(cp, qty);




            Pick one, otherwise it's pretty confusing.






            share|improve this answer













            public double costPrice get; set; 
            public double qty get; set;



            There is no point of having these two properties if you are passing those values to GetfinalPrice anyway:




            public double GetfinalPrice(double cp, double qty)

            return _strategy.calculate(cp, qty);




            Pick one, otherwise it's pretty confusing.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 1 at 14:06









            t3chb0t

            32.4k64399




            32.4k64399











            • I have modified the code. Now i am not sure how to pass the params to the gold and platinum strategy? I have hard coded the values.
              – krishna_v
              Oct 3 at 5:35










            • @krishna_v I have modified the code. - this is not good because you must not change it after receiving answers... you need to undo the edit... or someone else will do it :-]
              – t3chb0t
              Oct 3 at 5:37

















            • I have modified the code. Now i am not sure how to pass the params to the gold and platinum strategy? I have hard coded the values.
              – krishna_v
              Oct 3 at 5:35










            • @krishna_v I have modified the code. - this is not good because you must not change it after receiving answers... you need to undo the edit... or someone else will do it :-]
              – t3chb0t
              Oct 3 at 5:37
















            I have modified the code. Now i am not sure how to pass the params to the gold and platinum strategy? I have hard coded the values.
            – krishna_v
            Oct 3 at 5:35




            I have modified the code. Now i am not sure how to pass the params to the gold and platinum strategy? I have hard coded the values.
            – krishna_v
            Oct 3 at 5:35












            @krishna_v I have modified the code. - this is not good because you must not change it after receiving answers... you need to undo the edit... or someone else will do it :-]
            – t3chb0t
            Oct 3 at 5:37





            @krishna_v I have modified the code. - this is not good because you must not change it after receiving answers... you need to undo the edit... or someone else will do it :-]
            – t3chb0t
            Oct 3 at 5:37


















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f204676%2fapply-discount-changes-with-strategy-pattern%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay