Regardless of its size, I place each enumeration in its own file, with each enumeration having the namespace of the class(es) using it. I do this for a few reasons:
- It follows my preference for having many small classes and files over having fewer large ones.
- It’s consistent with how I handle classes and interfaces – and I see no reason why enumerations should be handled differently.
- Most importantly, it makes it easier to find the enumeration, particularly when you’re outside the IDE and can’t use its navigation features.
Others advocate placing the enumeration in the same file as the class that’s using it. But what happens when multiple classes use the same enumeration – do you then move the enumeration into its own file, or do you continue to keep the enumeration in the same file as one of the classes using it? Either way, it’s inconsistent and confusing. Another common approach is to place all enumerations within one file, with the enumerations all under a single namespace. Again, I feel this convention makes it harder to locate an enumeration, plus it moves the enumerations out of the namespaces they’re logically related to.
Thus I recommend placing each enumeration in its own file. But regardless of the approach you use, the most important thing is to have everyone on the team follow the same convention.
0 comments:
Post a Comment