Switch cases maximum implementation?

前端 未结 7 1721
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 12:27

I am using a single switch cases which will have more than 100 cases statement to be used. Are there any limit ?

The usage of cases are for the suggestions of my Aut

7条回答
  •  轮回少年
    2021-01-19 13:09

    Or you can have a look at the strategy pattern. For example:

    If it looks like this now:

    switch (calculation type)
    {
       case: Fibonacci { ... }
       case: Pithagoras { ... }
       ...
       case 104 : { ... }
    }
    

    You can refactor it using the strategy pattern maybe like this:

    CalculationStrategy strategy = strategyFactor.getStrategy(calculation type);
    strategy.doCalculation;
    

    Happy coding! Dave

提交回复
热议问题