Tag Info

Hot answers tagged

4

I use enums this way all the time. Enums are a great way to write immutable helper objects that you only need exactly one copy of; they help reduce the chance of memory leaks and easily group many related classes together in a clear way. What I would not do is expose the control of which particular BusinessLogic you're using to external classes using a ...


3

It may be a good idea to encapsulate behavior into a Java enum (or C++ enum class) when you find yourself writing switch statements like the following, especially when the switch is repeated in different parts of the code. MyEnum x = ...; switch (x) { case A: // Do something break; case B: // Do something break; case C: // Do ...



Only top voted, non community-wiki answers of a minimum length are eligible