lundi 31 mai 2021

Should an enum have 2 separate value sets if they are related?

This question is on the reuse of the Java Enums

Let's say I have an Enum

public enum Days {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY SATURDAY, SUNDAY
}

Now, in one of the business usecase, I also need to consider Today, Tomorrow and yesterday as Days. Though they are related concepts, but clubbing them in the same enum doesn't feel right.

Should we create a new enum or can there be any justification to overload the same Days enum and add these 3 values inside it.

public enum Days {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY SATURDAY, SUNDAY, TODAY, TOMORROW, YESTERDAY
}

Aucun commentaire:

Enregistrer un commentaire