Writing another question for SO, I came to a pattern that I use very often and I never really reflected about. But now, I’m no longer sure if this is the right way:
If I have collections that my WPF-controls will bind to, I returned almost always IEnumerable<SomeType>
. However internally , this is in most cases an ReadOnlyObservableCollection<SomeType>
. I never had a problem with this and all consuming controls always updated correctly, what is not astonishing because they check for the INotifyCollectionChanged
-interface.
But my question is now, if this is bad practice to declare in the signature only the IEnumerable<SomeType>
but to return (and also depend on) something much more powerful (INotifyCollectionChanged
).
Update:
I try to clarify:
My main intention is to return an IEnumerable<SomeType>
. But most of the time, the returned IEnumerable<SomeType>
implements also INotifyCollectionChanged
such as ReadOnlyObservableCollection<SomeType>
does. The consuming controls bind accordingly (what my second intention is).
Maybe I should have asked: Is there an interface that exactly contains IEnumerable and INotifyPropertyChanged.