Search code examples
javaenumsbusiness-logic

Business logic in Enums?


Is it considered good practice to put any type of business logic in Enums? Not really intense logic, but more of like convenience utility methods. For example:

public enum OrderStatus {

 OPEN, OPEN_WITH_RESTRICTIONS, OPEN_TEMPORARY, CLOSED;


 public static boolean isOpenStatus(OrderStatus sts) {
      return sts == OPEN || sts == OPEN_WITH_RESTRICTIONS || sts == OPEN_TEMPORARY;
 }

}

Solution

  • IMHO, this enables you to put relevant information right where it's likely to be used and searched for. There's no reason for enums not to be actual classes with actual responsibility.

    If this allows you to write simpler code, and SOLID code, why not?