Simple Way to Determine Pluralization of Package Name in Java and Rust
Ever been in a situation where you’re having a hard time naming the package of your code? For me it’s always, probably because I do have partial OCD/OCPD (Obsessive Compulsive Personality Disorder)1.
Anyways, I’ve found this answer before on StackExchange hopefully it’s still there and I’m using it ever since in naming my namespaces and packages.
It’s double the giggles and double the grins and double the trouble if you’re blessed with twins.
— Anonymous.
Just in-case it might get deleted here is the full answer:
Use the plural for packages with homogeneous contents and the singular for packages with heterogeneous contents.
A class is similar to a database relation. A database relation should be named in the singular as its records are considered to be instances of the relation. The function of a relation is to compose a complex record from simple data.
A package, on the other hand, is not a data abstraction. It assists with organization of code and resolution of naming conflicts. If a package is named in the singular, it doesn’t mean that each member of the package is an instance of the package; it contains related but heterogeneous concepts. If it is named in the plural (as they often are), I would expect that the package contains homogeneous concepts.
For example, a type should be named TaskCollection
instead of TasksCollection
, as it is a collection containing instances of a Task
. A package named com.myproject.task
does not mean that each contained class is an instance of a task. There might be a TaskHandler
, a TaskFactory
, etc. A package named com.myproject.tasks
, however, would contain different types that are all tasks: TakeOutGarbageTask
, DoTheDishesTask
, etc.
Here is the original answer link from Software Engineering StackExchange.
Should package names be singular or plural?
Check the original answer on stack exchange if there is an update.
- Obsessive–compulsive personality disorder (OCPD) is a cluster C personality disorder marked by an excessive need for orderliness, neatness, and perfectionism. Symptoms are usually present by the time a person reaches adulthood, and are visible in a variety of situations. ↩︎