mercredi 13 juillet 2016

What Java design pattern to use?

I am looking for a design pattern to clean up my code. I envision two child classes that inherit from the same abstract class or interface. One class will execute Steps 1, 2, 3A, 3B and 4. The second class (where 'isNewScenario' = true) will execute Steps 1, 2 and 4.

In other words, how do I get each of these classes to execute their required methods WITHOUT the sloppy if statement?

// Step 1: 
executeCommonStepOne();

// Step 2:
executeCommonStepTwo();


If (isNewScenario){
    // Step 3 A
    executeNewScenarioStepOne();

    // Step 3 B
    executeNewScenarioStepTwo();

}

// Step 4
executeCommonStepThree();

Thanks a bunch in advance!

Aucun commentaire:

Enregistrer un commentaire