Business logic in Enums?

I often use Enums for singleton instances. Thus they contain almost only business logic. Being classes that implcitly extend Enum they can even implement interfaces.

I'd only consider using Enums if it fits to the enumerated values, i.e. the buisness logic is tightly coupled with the instances.


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?


Yes, i think this is a good idea. However, i think it can be implemented much more cleanly using instance methods:

public enum OrderStatus {

 OPEN, OPEN_WITH_RESTRICTIONS, OPEN_TEMPORARY, 
 CLOSED {
   @Override isOpen() { return false; }
 };

 public boolean isOpen()
 { 
   return true;
 }
}