Where is the best place to locate enum types?

前端 未结 10 2133
自闭症患者
自闭症患者 2020-12-25 11:16

I have found that there is generally a singe type or namespace that takes in any particular enum as a parameter and as a result I have always defined those enums there. Rece

10条回答
  •  感动是毒
    2020-12-25 12:14

    I try to put everything associated with a class in the class. That includes not just enums, but also constants. I don't want to go searching elsewhere for the file or class containing the enums. In a large app with lots of classes and folders, it wouldn't always be obvious where to put the enum file so it would be easy to find.

    If the enum if used in several closely-related classes, you could create a base class so that the common types like enums are shared there.

    Of course, if an enum is really generic and widely used, you may want to create a separate class for them, along with other generic utilities.

提交回复
热议问题