一个属于领域实体的枚举,在Java项目中应该放在哪个包中?

huangapple go评论66阅读模式
英文:

Which package should an enum, which is a part of a domain entity, be kept in a Java project?

问题

在我的情况下,我有一个名为domain的Java包,其中包含JPA实体类。其中一个实体,比如说Employee,有一个属性叫做statusstatus属性的值始终来自集合{ACTIVE, INACTIVE},因此我已经定义了一个枚举类,名为Status

我知道这可能是一个小问题,但我在考虑这个枚举类(在关系数据库管理系统中没有映射表),是应该保留在domain包中,还是应该放在其他地方,以便domain包仅包含实际的领域类。

英文:

In my case, I have a java package - domain with JPA entity classes.
One of these entities, say Employee, has an attribute - status. status will always be from the set {ACTIVE, INACTIVE}, hence I have defined an enum - Status.

I know this is a small thing, but I was thinking whether this enum (which has no table mapped in the RDBMS database), be kept in domain package itself, or should it be kept somewhere else so that domain contains only the actual domain classes.

答案1

得分: 1

简单地说,这取决于你的喜好。

如果这个枚举只用于定义单个类(在你的情况下是 Employee)的状态,那我会将它放在 domain 的子包中。

例如:

  • *.domain.enums(用于所有这种类型的枚举)
  • *.domain.model(用于所有实体类)
英文:

Simple put it depends on your taste.

If this enum is only used for the purpose of defining the status of a single class - in your case Employee then I would put it in a subpackage of domain.

For example:

  • *.domain.enums (for all enums of that kind)
  • *.domain.model (for all entity classes)

huangapple
  • 本文由 发表于 2020年10月13日 20:55:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/64335726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定