Where to put enumerations in a Java project?
domain-model, java
Solution
In the project I am on at work, we defined a "types" package and placed our enums there near our core domain model entities. The types have references to each other in certain cases and are useable on their own as well as with the domain entities, so while I would prefer that they were in the package of the core domain model, it does allow for the core domain model package not to grow too big (the types package has a lot of enums).
For instance, given com.companyname.core.domain.model
We would also have a com.companyname.core.domain.types
package that was used for the core domain types.
The reason for "types" was that we would postfix the enum with "Type" so that it was immediately obvious that it was in fact an enum denoting a particular type of feature. This helps with Eclipse's type search (and probably other IDEs), although I suppose others would state that appending type is redundant given the package name.
We also included ORM mapping classes in the types package to convert to and from database representations (with the types using internal integer codes, not the ordinal, to represent them - just in case someone rearranged them or a constant was no longer needed and should be deleted).
Problem
We put entities in a domain package. Something like com.acme.domain or com.acme.model. Entities often have properties which represent codes, rather than free form strings. Something like a sort order code (ASC or DESC) or publish status code (DRAFT, SUBMITTED, PUBLISHED). I create enums for these, so I can make decisions in "business logic". Question is: where do we put these enums? The same package as entities or a different package like com.acme.domain.support? When you provide an answer, please explain why you'd put enum in one package vs another.