Refactoring if/else logic

前端 未结 14 646
醉话见心
醉话见心 2020-11-30 01:38

I have a java class with a thousand line method of if/else logic like this:

if (userType == \"admin\") {
     if (age > 12) {
          if (location == \"         


        
14条回答
  •  猫巷女王i
    2020-11-30 02:28

    You could make userType an enum, and give it a method that performs all of your "do something slightly different" actions.

提交回复
热议问题