If we have a parent class Vehicle and its child classes as Bus, BiCycle, MotorBike.
At a certain point of time in a service class, I will be getting all the objects like List vehicles.
My Business logic should be like below, A list of faulty vehicles will be received and for each vehicle type, a respective mechanic should be allocated.
If I receive a bicycle it should go to a bicycle mechanic or other vehicle and their respective mechanics.
It looked bad when I used to switch case and if else conditions.So I tried to use the Visitor pattern and Factory pattern, Factory pattern also will use either switch or if-else conditions to get the object dynamically and call the overridden method. Currently using the visitor pattern.
Kindly suggest some approach which would work better with this case.
Aucun commentaire:
Enregistrer un commentaire