mardi 8 janvier 2019

What is the alternative way available for the If condition in Java using Factory Pattern?

GetPropertyValues properties = new GetPropertyValues();
Adapter = properties.getPropValues();

case 5:
    System.out.println("Enter color of car");
    color = sc.next();
    System.out.println("Enter Registration Number");
    reg_number = sc.next();
    car.setColor(color);
    car.setRegistrationNumber(reg_number);
    parkingSlotManager.emptyParkingSpace(Adapter,car);

    break;

public void emptyParkingSpace(String Adapter,Car car) {
   if (Adapter.equalsIgnoreCase("memory")) {
      ArrayList<ParkingSlot> filledSlots =       getFilledParkingSlots();
      for (ParkingSlot parkingSlot : filledSlots) {
         if (parkingSlot.getCar().equals(car)) {
            parkingSlot.setCar(null);
        parkingSlot.setFilled(false);
         }
      }

   }
   if(Adapter.equalsIgnoreCase("mongodb"))
   {
      collection.remove("{registerNumber:'" +     car.registrationNumber + "'}");
   }
}

The question is to write a Factor Pattern for the if condition in the class emptyParkingSpace for checking of the Adapter and using the appropriate class to work

Aucun commentaire:

Enregistrer un commentaire