Hello
Observer design pattern well described here: WIKI: Observer pattern
I wish give some real example.
So, example...
My example is: GUI for creating controls + share information between:
My UI is very simple: 2 buttons + text box:
Add listener button, which create UserControl and subscribe it
Remove listener: remove UserControl and detach it
Text box: when it updates, each UserControl get informed about new text
UserControl:
Lable: show Subject status
TextBox: can be updated, so updated text goes to Subject and from Subject to each Observer:
And, if i wish talk with pictures:
Start app:
And, 1-st listener can set its text ("mama") in its textbox:
Now, main UI set new text ("papa") in its textbox, so each listener get it ("papa") and show in own lable:
Code
Solution:
Observer design pattern well described here: WIKI: Observer pattern
I wish give some real example.
So, example...
My example is: GUI for creating controls + share information between:
My UI is very simple: 2 buttons + text box:
Add listener button, which create UserControl and subscribe it
Remove listener: remove UserControl and detach it
Text box: when it updates, each UserControl get informed about new text
UserControl:
Lable: show Subject status
TextBox: can be updated, so updated text goes to Subject and from Subject to each Observer:
And, if i wish talk with pictures:
Start app:
Add listener:
Add 1 more listener:
Now, main UI set text ("hello") in its textbox, so each listener get it ("hello") and show in own lable:
and we see, "mama" is updated for each listener
Code
Solution:
IObserver.cs:
ISubject.cs:
Subject.cs:
UserControl1:
Form1:
Thats all
Thanks,
Efim
No comments:
Post a Comment