mercredi 23 juin 2021

How to call a method at runtime based on a string value using springboot/ any java design?

Consider below example, I want to call appropriate produce method based on vehicle, where vehicle can be "car" or "bike" or "van"

Class Company {

public void manufacture(String vehicle) {

   //How to call appropriate **produce** method based on string(vehicle) passed as param in this method **without using if or switch condition here**?

}

}


Class AutoMob {

public void produce(Car c, ....){

}

public void produce(Bike b, ....){

}

public void produce(Van l, ....){

}

}

I dont want to use reflection or condition here and looking for design based approach or any idea using springboot?

Thanks in advance!!





Aucun commentaire:

Enregistrer un commentaire