Let's say that there are two properties in a business model for eg., country and type, and we need to handle different logic for each country and for each type.
if(country=="us"){
if(type=="type1){
usType1Handler.Execute();
}
else if(type=="type2"){
usType2Handler.Execute();
}
.
.
.
else{
usDefaultHandler.Execute();
}
}
else if(country=="uk"){
if(type=="type1){
ukType1Handler.Execute();
}
else if(type=="type2"){
ukType2Handler.Execute();
}
.
.
.
else{
ukDefaultHandler.Execute();
}
}
else{
throw exception("unknown country");
}
There will be lot of if's to mix and match the each implementation specific to each country type combination. Is there any design pattern we can use to handle this scenario?
Aucun commentaire:
Enregistrer un commentaire