DEV Community

Discussion on: Use POCOs to group data and logic - there’s more to life than services and DTOs

Collapse
mhduke profile image
mhDuke

hi João :)

Uri class is very good example. in regards to collections i always expose IEnumerable and sometimes IReadOnlyList if index access is required. thanks for sharing.

Collapse
joaofbantunes profile image
João Antunes Author

I think collections is a bit of an adjacent topic, but yes, choosing the one that better fits the needs is important and quite often ignored (e.g. due to the ease of LINQ, many times people just use lists for everything when maybe a Dictionary or a Set would be better choices).

On that note, I usually try to avoid IEnumerable unless I specifically want something that might be lazy. In other occasions (e.g. a result from a repository or service call) I prefer using an IReadOnlyCollection which fits better with the already computed collection premise.