Which Java Design Pattern fits best for if-else statement including loop?

后端 未结 4 784
攒了一身酷
攒了一身酷 2021-01-24 04:55

I have a use case with 7-8 if else. Sample use case:

 String type;
 List < Entity > entityList;


 if (type.equals(\"A\")) {
    ClassA a = new ClassA();
          


        
4条回答
  •  走了就别回头了
    2021-01-24 05:13

    If you really want to use a design pattern in this case I would suggest the Visitor Pattern. This is the one (as far as I know) which is best suited for this kind of "type-checking". You can find an good example here. But as alreday stated in the comments, I agree that a pattern would be to much overhead in this case.

提交回复
热议问题