lundi 17 décembre 2018

Splitting an enum into classes

I have the following enum

public enum MyEnum {
    NAME("Name", "Good", 100),
    FAME("Fame", "Bad", 200);

    private String lowerCase;
    private String atitude;
    private long someNumber;

    MyEnum(String lowerCase, String atitude, long someNumber) {
        this.lowerCase = lowerCase;
        this.atitude = atitude;
        this.someNumber = someNumber;
    }
}

I need to refactor it into classes, my idea is something along the lines of this:

abstract class MyEnum {
    public abstract String getLowerCase();
    public abstract String getAtitude();
    public abstract long getSomeNumber();
}

class MyEnumName extends MyEnum {
    public String getLowerCase(){}
    public String getAtitude(){}
    public long getSomeNumber(){}
}

class MyEnumFame extends MyEnum {
    public String getLowerCase(){}
    public String getAtitude(){}
    public long getSomeNumber(){}
}

But I feel like i am over complicating it and i really want to do it with best practices in mind. Would this be a correct solution or if it is not which pattern would be suitable for this.

Aucun commentaire:

Enregistrer un commentaire