vendredi 7 octobre 2022

Design pattern for if-else with common logic within the conditionals

I have to implement a solution where the code behaves differently according to a different condition.

For example:

if(condition) {
   //create one object
} else {
   //create another object
}
someCommonMethod();
if(condition) {
   //do one thing
} else {
   //do another thing
}
someCommonMethod();

Even the code inside the conditions is shared sometimes, it's just slightly variations of it. What would be the best approach here? What would be the best Design Pattern?

Aucun commentaire:

Enregistrer un commentaire