jeudi 22 novembre 2018

How can I split a methods functionality using an enum as condition?

I have the following code:

enum Example {

    ex1,ex2

}

public void method(Example exType) {

    if(exType.equal(ex1)) {
        //do similar stuff
    } else if (exType.equals(ex2)) {
        //do similar stuff
    } else {
        //throw exception
    }

}

The problem is the method calls other methods that behave in the same way. So it doesn't look very good as an implementation. How can i split this behavior?

Aucun commentaire:

Enregistrer un commentaire