Alternative for switch that only calls methods based on cases values

后端 未结 4 583
醉话见心
醉话见心 2021-01-19 03:59

Is there a possible way to write the next switch in some shorter, readable code?

switch (SomeValue)
{
  case \"001\": return DoMethod1(); break;
  case \"002         


        
4条回答
  •  甜味超标
    2021-01-19 04:26

    In general a good alternative for switch would be using State Design Pattern other good alternative is Strategy Pattern. It will make your code more extensible and is more object oriented approach.

提交回复
热议问题