English 中文(简体)
Enum practices - Define within a category/separately, make public/ private
原标题:Enum practices - Define inside a class/separately, make public/private
  • 时间:2011-06-26 12:47:05
  •  标签:
  • java
  • enums

在界定um时有什么良好做法?

例如,我有一个人班。 就这一类而言,我选择使用一种具有《仲裁示范法》和《公平贸易法》价值的内容。

Should the enum be defined inside the Person class or separately? Should the enum be defined as private or public? Also, do you have any further advice that would make using an enum as flexible as possible?

最佳回答

IMHO, 使之成为public sign enum within Person

因此,“性别编码”只适用于个人,因此,在其中将人重新联系在一起(性别在个人的情况下没有用处)。

The upside:

  • less class bloat
  • if you move Person to another package/project, Gender will always come with it
  • Person, who is the only user, has "control" of it and may alter it as it wants, eg
    • adding private List<HealthIssue> genderSpecificHealthIssues;
    • adding more enums, eg TRANSGENDER, INTERSEX, or whatever

唯一的下层是,你必须使用<条码>。 进口 com.company.Person.Gender.*;。

在许多JDK类别中,例如Calendar ,其中界定了它使用的许多与日期有关的常数。 班级。

问题回答

为了充分的灵活性,加上静态等级。 当然,这只是为了在整个申请过程中需要使用的遗体。 对于地方和专门领域来说,让它们接近其使用的地方是较好的。 <>Exampli gratia,我有一个IPHandler级班,使IPv4和IPv6的操作、分类和翻译工作对班级用户具有透明度(IPHandler是一个固定班)。 它有一个 en,即IPType,其数值为IPv4和IPv6,只在IPHandler用于几个业务。 由于它没有在其他地方使用,因此在IPHandler语中作了定义。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签