Is it good practice to return an IEnumerable <T> for a collection that implements INotifyCollectionChanged
After writing another question for SO, I came up with a pattern that I use very often, and I never thought about it. But now I'm not sure anymore that this is the right way:
If I have collections that my WPF controls bind to, I almost always returned IEnumerable<SomeType>. However, internally it is in most cases ReadOnlyObservableCollection<SomeType>. I never had a problem with this, and all consumer controls were always updated correctly, which is not surprising, because they check the interface INotifyCollectionChanged.
But now my question is, if it is bad practice, to declare in the signature only IEnumerable<SomeType>, but return (and also depend on) something much more powerful ( INotifyCollectionChanged).
Update:
I am trying to clarify:
My main intention is to return IEnumerable<SomeType>. But most of the time the returned one IEnumerable<SomeType>implements also INotifyCollectionChanged, for example ReadOnlyObservableCollection<SomeType>. Consumption controls are related accordingly (what is my second intention).
Perhaps I should ask: is there an interface that exactly contains IEnumerable and INotifyPropertyChanged.
, IEnumerable<T> INotifyCollectionChanged - - . , . API . , , - , .
ObservableCollection<T> ( Collection<T>), IList<T>, .
, IEnumerable<T> ( IList<T>, ) INotifyCollectionChanged. , , .
( )
, , , API, . , - . , , .
, , , "" . , IEnumerable<T> INotifyCollectionChanged - , . , , "" .
,
IEnumerable<SomeType>, ( ) (INotifyCollectionChanged)
, .
IEnumerable, - , , , , , .
IEnumerable - ! , - , !
ReadOnlyObservableCollection, - , , .
ReadOnlyObservableCollection , .
IEnumerable.
IEnumerable INotifyPropertyChanged IEnumerable INotifyPropertyChanged - .
,
IEnumerableINotifyPropertyChanged
, ReadOnlyObservableCollection.