英文:
Which package should an enum, which is a part of a domain entity, be kept in a Java project?
问题
在我的情况下,我有一个名为domain的Java包,其中包含JPA实体类。其中一个实体,比如说Employee,有一个属性叫做status。status属性的值始终来自集合{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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论