When reading this question I started to wonder a bit. Say you have these two:
class ProductCollection : ICollection<Product>
class ProductList : IList<Product>
What would you call one that were an IEnumerable<Product>
?
class Product--- : IEnumerable<Product>
Before I read that other question I might have called it a ProductCollection
actually, but taking the new info into account, that would have been a bit misleading since it does not implement ICollection<Product>
. Could you call it Products
?
var products = new Products(); // products is/are products
Almost works but sounds a bit strange... What would you call it?
You generally do not base the name of a class off any interface it implements. (Which one do you choose when there are multiple ones, for a start?) It is quite typical to base it off an inherited class, but more often simply on the purpose of the class, and certainly not the interface. (The interface might be named after the class, if anything.)
Your example is somewhat invalidated by the fact that a well-designed ProductCollection
should implement ICollection<Product>
and IEnumerable<Product>
while a well-designed ProductList
should implement both those interfaces as well as IList<Product>
.
If you look in the BCL of the .NET Framework, you should notice that this is precisely the case. The List<T>
class implements all three interfaces, as does the Collection<T>
class (though note that in the general case a 'collection' need not implement IList<T>
).
I think that "Sequence" would be a good suffix.
If it only implements IEnumerable<Product>
, then I would name it ProductEnumeration
, but I would feel free to name an instance of it products
. On the other hand, I don't recall ever creating a class that only implemented IEnumerable<T>
. Doesn't seem to be much point if you can't add stuff to it and if you can, then I'd derive from one of the collection classes that implements IEnumerable<T>
and inherit that behavior, too.
If I were returning an enumeration of Product entities, I'd simply return it as IEnumerable<Product>
without having a special class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With