From a OO perspective, are enums supposed to be within a separate class? I have seen a few examples of this. I am wondering if this is the correct way to do it? (just trying to learn the 'proper' way of doing things.
-
If you use your enum only in one class, it can be an "inner enum". Most often you'll end making it public but refactoring is cheap and easy.Denys Séguret– Denys Séguret2014-05-06 11:50:32 +00:00Commented May 6, 2014 at 11:50
Add a comment
|
4 Answers
There is no universally "proper" way of defining enums - it goes the same way as other entities that can be nested or could exist on their own, such as classes and interfaces.
- When your
enumis intended for use only with a particular class, for example, to enumerate options of one of its methods, definingenuminside the class is reasonable - When your
enumis intended to be shared among multiple classes, define it at the top level.