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:

  1. Connect to the forum database and start a forum session
  2. Retrieve forum posts and comments
  3. 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?

  • 9
    They are a code smell. Notice that you listed three things that the ForumService does. It sounds like the reason it has an ambiguous name is that the class does more than a single thing and so the class itself is ambiguous. If the responsibilities were more clearly encapsulated then you would not have this issue. It's sounds like you need ForumSession, ForumRepository, and ForumFactory classes instead. – RibaldEddie Dec 7 '14 at 22:04
  • 1
    I think he's just asking for a naming convention. Usually if I add anything to the name its just 'Class'. So the class would be called 'Forum' or 'ForumClass', depending on the language begin used. – GrandmasterB Dec 7 '14 at 22:32
  • @RibaldEddie a great point! I hadn't thought of that. – Big McLargeHuge Dec 7 '14 at 22:38
  • 3
    @rwong "affectionate, cuddly, helpful and supportive" - what???? – Big McLargeHuge Dec 7 '14 at 23:20
  • 1
    @MichaƂKosmulski Which is why I said it depends on the language. There is no language tag on the question. It would not be uncommon to have a file full of functions in a Pascal file, for example. In Java it'd be superfluous, but in other languages not so much. – GrandmasterB Dec 8 '14 at 18:58

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.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.