I work on a lot of projects with different teams. Every project has its own conventions, including what to call arbitrary classes that don’t lend themselves to obvious names.
As a counter-example, it’s usually pretty obvious what you should name your models (UserModel, AlbumModel, etc.). The same goes for repositories, installers, controllers and views.
But inevitably there are classes that aren’t as clear-cut. For example, I’m working on a project right now that has a ForumService that does the following:
- Connect to the forum database and start a forum session
- Retrieve forum posts and comments
- Create posts and comments
At first, the name ForumService made sense. But then I read more about service-oriented programming and realized that many developers may consider a service to be something different entirely (like a web service). So now I’m considering whether I should call it ForumProvider or just Forum.
The team I work with full-time likes to name classes like this “Tasks” (e.g. AuthenticationTasks, UserTasks). We also have a lot of “Helpers” (e.g. ViewHelpers) and “Utilities” (e.g. HtmlUtilities) for smaller classes. Some developers don’t like these ambiguous names just because they’re ambiguous.
What do you normally use and why? Do most people generally prefer to avoid names like “Helpers” and “Utilities”, and is there a good reason?
11
Naming things can be tricky – A good rule of thumb is that if you are having trouble naming a class/function clearly then you should read it as a red-flag that you haven’t thought about the architecture or design enough yet and should probably stop coding until you have.
For naming stick to the name of the object/concept being modelled and exclude the design patterns / non-object names for classes unless there is a specific reason to include them. Some examples are…
- the class is purely or primarily implementing that pattern like
SomethingFactory
. - a distinction is needed to avoid ambiguity like
StringBuilder
. - the architecture (mvvm/mvc/mvp etc) uses it as a convention like
DisplayPostViewModel
.
In the case of your class it sounds like you’re best off using something like Forum
since that is the concept you’re modelling. You’d then need classes for the various objects it needs Post
and Template
for example. You may want a ForumFactory
to create the forum object and create a Dal
object for it.