What is a good example of the power of interface events (declaring events inside interface)?
Most of the times I have seen only public abstract methods inside interface.
What is a good example of the power of interface events (declaring events inside interface)?
Most of the times I have seen only public abstract methods inside interface.
INotifyPropertyChanged is used through out the framework.
Just look at the INotifyPropertyChanged.PropertyChanged Event
I used events to signal when a serial port received data.
Here is my interface.
Events in interfaces work pretty much just like methods. You can use them just how you would use any interface.
A classic scenario is MVP pattern with passive view. The form implememts an view inteface that has a NameChanged event. The presenter that creates/uses the view subscribes to this event. When the name text in textbox is changed view fires this event. The presenter is then notified. Since the presenter only knows about event from view interface you can provide a mock view for testing. The view is completely decoupled from presenter.
An excellent example within the .NET framework is the INotifyPropertyChanged interface. This interface consists of only one member: the PropertyChanged event.
In WPF, you can state that a control will display a specific property of an object instance. But how will this control update if the underlying property changes?
If the bound object implements the INotifyPropertyChanged interface, the WPF framework can just listen to PropertyChanged and update appropriately.
here is one example
I have some code like this in 1 of my applications. The app was written in winforms, then upgraded to WPF.