I have something like this:
switch(type){
case "CAR":
return new Car();
case "BIKE":
return new Bike();
}
Now, there is a requirement, to add a common API for both to check if input type is valid, only when validateFlag is true.
Can you suggest some design here? What's the best to go with?
I am thinking of something like:
if(flag== true)
return new Validator();
switch(type){
case "CAR":
return new Car();
case "BIKE":
return new Bike();
}```
CarandBike, which makes sense, but returning aValidatordoesn't make much sense if you can also return aCaror aBike.