C#: Что Вы назвали бы классом IEnumerable?

AppcompatTextView теперь поддерживает автоматическое изменение размеров, начиная с библиотеки поддержки 26.0. TextView в Android O также работает аналогично. Больше информации можно найти здесь. Простое демо-приложение можно найти здесь здесь .



      


7
задан Community 23 May 2017 в 10:31
поделиться

9 ответов

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 and IEnumerable while a well-designed ProductList should implement both those interfaces as well as IList.

If you look in the BCL of the .NET Framework, you should notice that this is precisely the case. The List class implements all three interfaces, as does the Collection class (though note that in the general case a 'collection' need not implement IList).

6
ответ дан 6 December 2019 в 10:02
поделиться

I think that "Sequence" would be a good suffix.

6
ответ дан 6 December 2019 в 10:02
поделиться

Это будет зависеть от контекста, например, это может быть ProductsCatalog (подразумевая, что IEnumerable доступен только для чтения).

] В более общем смысле это может быть ProductsView . Конечно, полученные Продукты можно изменить, но я считаю, что это "звучит" уместно, тем не менее.

2
ответ дан 6 December 2019 в 10:02
поделиться

The problem here is that List or Collection impose they behave that way. But IEnumerable is very generic, not only in the C# meaning of generic. Every implementation can be behind it.

Some suggestions:

  • ProductIterator: This iterates Products.
  • ProductRetriever: This retrieves Products.
  • ProductCreator: This creates new Products at runtime.
0
ответ дан 6 December 2019 в 10:02
поделиться

If you look at the types in the .NET Framework that implements IEnumerable, I would say that the most common suffix is Collection, followed by the plural form of what the list contains. Then there are a number of "special cases" (such as Queue and Stack). I would personally vote for Collection as a first-hand choice.

0
ответ дан 6 December 2019 в 10:02
поделиться

In almost every case I can think of from my own experience, I haven't had to think of a name. The compiler does it for me, because I write an iterator method instead of writing a class by hand. And for the method name, it seems natural to just make it a plural word describing the sequence.

0
ответ дан 6 December 2019 в 10:02
поделиться

If it only implements IEnumerable, 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. 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 and inherit that behavior, too.

If I were returning an enumeration of Product entities, I'd simply return it as IEnumerable without having a special class.

5
ответ дан 6 December 2019 в 10:02
поделиться

Как kek444 Думаю, мне нужно спросить, что еще он делает? Он реализует IEnumerable <>, но это еще не все, иначе вам не понадобится класс, верно? Это сборник? Преобразует ли одно перечислимое в другое (изменение порядка, выбора, генерации и т. Д.)?

0
ответ дан 6 December 2019 в 10:02
поделиться

Я бы сказал Коллекция . Он может предложить ReadOnlyCollection или ObservableCollection, но он хорошо описывает класс. В конце концов, это набор продуктов (независимо от типа, лежащего в основе).

Чтобы решить этот и другой вопрос, используйте это;)
http://www.classnamer.com/

0
ответ дан 6 December 2019 в 10:02
поделиться
Другие вопросы по тегам:

Похожие вопросы: