89

It is always difficult for me to choose between singular and plural forms for classes names:

CustomerRepository vs. CustomersRepository
CustomerService vs. CustomersService
CustomerController vs. CustomersController

And for composite names it is even more difficult:

OrderCustomerRepository vs. OrderCustomersRepository vs. OrdersCustomersRepository

What approach do you prefer and why?

SiberianGuy
  • 4,823

4 Answers4

95

Use singular. The tool to turn screws with is called "screw driver" not "screws driver".

However, pluralize your method and property names accordingly, to indicate whether one value or a collection of them will be returned.

jmq
  • 6,108
back2dos
  • 30,140
91

The only thing I pluralize is collections.

foreach (var customer in customers)
{
    // do something with customer
}

All of your examples are individual objects, so they are not pluralized. Yes, the names refer to objects that might have multiple instances, but all you need to know in the name is the object entity (i.e. customer).

So in all of your examples, the singular is the correct form. Makes life much easier.

Robert Harvey
  • 200,592
13

Definitely singular. You don't create an object of People, you create a collection of Person objects. The only time I would use plurals would be for static classes, i.e. SupportServices, StringUtils, etc. However in this case, the class acts more as a namespace than anything else.

Rob
  • 430
3

Remember, a class is a template for an object. So think about the object that you are referring to.

Often it is a singular entity, especially when it is an ORM entity. Sometimes it could be a collection.

I believe the answer is specific to the context.

indi
  • 141