title: Switch between the tables and save data by considering a Specific field using strategy pattern
body: <p>There are three Tables named as car_details, bike_details, truck_details the fields are same for all the three tables (RegistrationNo, No.ofYearsOld, OwnerName, ContactNo, VehicleType) the field VehicleType should specify type of the vehicle(car or bike or truck) and its default value is car.</p>
  
  <p>All three tables have their separate POJO and repository</p>
  
  <p>The task is I need to save the data into the corresponding table by considering the vehicleType field.</p>
  
  <p>In My controller </p>
  
  <pre><code>@RequestMapping (value = "/createVehicle/", method = RequestMethod.POST, consumes = "application/json")
   @ResponseBody
   public ResponseEntity&lt;&gt; createGeneralAuthentication (@RequestBody CarDetails carDetails) {
  
  
          public void roleSelector(String type) {
  
              switch (type){
                  case "car":
                      return new CarRepository();
                  break;
                  case "bike":
                      return new BikeRepository();
                  break;
                  case "truk":
                      return new TruckRepository();
                  break;
              }
          }
     RolesRepository rolesRepository = new roleSelector(carDetails.getType());
  
          try {
              rolesRepository.save(carDetails);
          } catch (Exception ex) {
              return new ResponseEntity&lt;&gt;(HttpStatus.NOT_FOUND);
  
          }
              return new ResponseEntity&lt;&gt;(HttpStatus.OK);
      }
  </code></pre>
  
  <p>No if else should be used it need to be a strategy pattern.</p>