This is always a problem for me. Say, in a game, there's a class representing an enemy spacecraft named EnemySpacecraft
and there's a class representing some collection of those, say all that exist in the game. This class may be implemented as just an encapsulated array of enemy spacecrafts. Giving this class a name like EnemySpacecrafts
is way too similar to the singular form. My other ideas are e.g. AllEnemySpacecrafts
or EnemySpacecraftCollection
, but I don't know how good I would say those are. What is a proper name to give here? Is there a convention I'm unaware of?
Naming Conventions – Naming a Class Representing a Collection of Objects
naming
Best Answer
Welcome to worse part of this job. Naming things.
Here some suggestions
1. Reusability
Let's say you want to reuse the concept of groups for different entities of the game.
You could use a basic name alongside with generics
They also remain loyal to the games jargon (God, how I miss MMOs).
2. Concreteness
One benefit of omitting the suffix Collection is that you don't tie the name solely to the idea of having just a collection. A
Raid<?>
might involve behaviors and attributes like any other entity in the game.What I like about this approach is that you are moving the ubiquitous language of the domain (games) to the code.
If you think that the domain specific (yours) language doesn't matter and everything can be subordinated to the technical language, then...
The ideal name would be EnemySpacecraftRepository. But I get the feeling that it doesn't meet your expectations regarding this subject.