Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
Would the class contain a repository for multiple customers? If it's one repository for one customer... –  JeffO Aug 25 '11 at 21:36
1  
@Jeff O, repository can contain GetCustomerById and GetCustomers methods at the same time –  Idsa Aug 25 '11 at 21:37
2  
In Data Modeling, a table name should be singular. If your application is using domain classes that correspond 1-1 to your data model then it may be a good idea to keep the naming singular. Of course mapping classes to tables in 1-1 fashion may not be the best way to build your object model for an OO application, but this is beside the question. –  Emmad Kareem Aug 25 '11 at 23:26
add comment

4 Answers

up vote 41 down vote accepted

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.

share|improve this answer
1  
I'd use customerCollection for collections, but for the rest of it I agree. This is a best-practice in database design and works quite good in code also. –  Jan_V Aug 28 '11 at 12:24
5  
I dislike words like "Collection" here. English has a perfectly good way of referring to a collection of things, using plurals. –  Steven Burnap May 13 '12 at 3:26
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
And to think, all this time I've been using Peoples collections! –  Jordan Aug 26 '11 at 5:18
1  
List<person> people ... seems ok to me, @Jordan. –  StevenV Aug 28 '11 at 14:37
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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