dimanche 3 décembre 2017

figuring which design pattern to use?

in most radio devices,we can configure the wave which we want to explore and listen to stations using the demodulation mode compatible with this type, there are at least two types AM and FM we can model the radio device in this case as the following:

class RadioDevice {
    void demodule (String m) {
        if(m.equals("FM")
            /* FM modelation */
        else if(m.equals("AM")
            /* AM modelation */
    }
}

how can I apply the strategy pattern in this case?

Aucun commentaire:

Enregistrer un commentaire