Refactoring if/else logic

前端 未结 14 647
醉话见心
醉话见心 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
    慢半拍i (楼主)
    2020-11-30 02:27

    without more information there is no good answer

    but fair guess would be this: use OO

    first define a User, define Admin, Student and all other types of users and then let polymorphism take care of the rest

提交回复
热议问题