Re: Naming convention for collection of objects
agarwal.harsh2@gmail.com wrote:
Not to sound nit-picky, but our team is debating on the right naming
convention for classes that have an aggregated collection (list, set,
map, array etc).
For example, take class Car. Now we need a class that is a collection
of cars.
Two schools of thoughts are:
1. Name the class CarCollection.
Pros. Very clear - it's a collection of cars.
Cons. Does Collection indicate that it will have an aggregated
"Collection" object (Java collection as compared to a Java Map)
2. Name the class Cars (notice the plural)
Pros. No confusion as to whether there is a Collection inside it,
or a Map.
Cons. Difficult to read maybe - Car and Cars look similar.
Any opinions?
Not #1. People can read the type separately from the name.
So #2 but preferable with variant that adds more difference
between the two. Car and CustomerCars/CarInventory/whatever.
Note that it is often a bad idea to have a class that only
acts as a holder of a collection, because it really adds
little value.
Arne