title: Replace switch-case with polymorphism
body: <p>I know there are similar questions already, but looking at them I still have some doubts about how I should design my code. I have a service that allows for <code>User</code> <em>registration / login /update / delete</em>. The thing is that the <code>User</code> is an abstract type, which contains the data <code>typeOfUser</code> based on which the actual <em>registration / update / delete</em> methods should be called, and right now I do that in a <code>switch-case</code> block. I'd like to replace that with some better design.</p>
  
  <p><strong>UserController.java</strong></p>
  
  <pre><code>public class UserController {
  
      public UserDto register(UserDto user) {
          switch(user.getTypeOfUser()) {
          case DRIVER: return driverService.register(user);
          case CUSTOMER: return customerService.register(user);
          // ...
          }
      } 
  
      public UserDto update(UserDto user) {
          switch(user.getTypeOfUser) {
          case DRIVER: return driverService.update((DriverDto) user);
          case CUSTOMER: return customerService.update((CustomerDto) user);
          // ...
          }
      }
  
      public UserDto login(long userId) {
          loginService.login(userId);
  
          UserBO user = userService.readById(userId);
  
          switch(user.getTypeOfUser) {
          case DRIVER: return DriverDto.fromBO((DriverBO) user);
          case CUSTOMER: return CustomerDto.fromBO((CustomerBO) user);
          // ...
          }
      }
  
      // ...
  }
  </code></pre>
  
  <p>I understand that something like <code>Visitor</code> pattern could be used, but would I really need to add the methods of <em>registration / login /update / delete</em> in the <code>Enum</code> itself? I don't really have a clear idea on how to do that, any help is appreciated.</p>