mercredi 7 juin 2017

How to completely get rid of if-else with OOP in such a tree like structure?

Here is the psudeocode:

if (parttimeEmployee) {
    if (country == USA) {

    } 
    if (country == UK {

    }
}

if (fullTimeEmployee) {
    if (country == USA) {

    } 
    if (country == UK) {

    }
}

Now, partTime and fullTime employees can be subclassed from 'Employee' interface.

But we have another if-else repeated/replicated inside each of them for 'Country'

Which design-pattern can we use to completely replace such nested-conditions ?

Aucun commentaire:

Enregistrer un commentaire