Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use Plural vs Collection word on Methods

I'm creating an API for a module and after I created several methods inside my classes, I asked myself this question.

Right now, and as an example, I'm doing this:

public Company GetMonitoredCompany( String companyName ) { ... }
public List<Company> GetMonitoredCompanies( ) { ... }

But I realize that for several times that I use other API's / Services sometimes they have Collection in the name maybe like:

public List<Company> GetMonitoredCompanyCollection( ) { ... }

is there a rule for this? a pattern? or either way should be ok?

like image 391
balexandre Avatar asked Oct 29 '25 04:10

balexandre


1 Answers

Use the shortest, simplest name that clearly shows the methods purpose. And be consistent within your project.

In this example, if there are no other considerations, I would use the name:

GetMonitoredCompanies

Because it's shorter and clearer.

(I would also return a read-only ICollection or IEnumerable unless you've got some specific reason not to.)

like image 159
Chris Avatar answered Oct 31 '25 19:10

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!