In reading about the Observer design pattern, I noticed that it is implemented using interfaces. In Java, the java.util.observable implementation is also a class. Shouldn't the C# and Java versions use interfaces ?
Scott
An ObservableCollection is a dynamic collection of objects of a given type. Objects can be added, removed or be updated with an automatic notification of actions. When an object is added to or removed from an observable collection, the UI is automatically updated.
According to the C# Programming Guide, an interface cannot contain an implementation: When a class or struct implements an interface, the class or struct must provide an implementation for all of the members that the interface defines.
Yes, it is mandatory to implement all the methods in a class that implements an interface until and unless that class is declared as an abstract class.
The practical difference is that BindingList is for WinForms, and ObservableCollection is for WPF. From a WPF perspective, BindingList isnt properly supported, and you would never really use it in a WPF project unless you really had to.
Well, it implements INotifyCollectionChanged
and INotifyPropertyChanged
. However, interestingly, it doesn't implement the new IObservable<T>
interface from .NET 4.0, which you might have expected.
It would arguably be useful for there to be a generic form of INotifyCollectionChanged
... but I don't know of one.
But they DO use interfaces. The ObservableCollection in .NET is an implementation of the interfaces - you are free to ignore it and to your own implementation.
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