Views: 19.2K
Replies: 2
Archived
|
Delegate (C#) versus Observer Pattern?I have a question: Is the delegate in C# equivalent to the Observer Pattern? If not, what is the difference?
Thanks in advance. Asmprogs Asmprogs, Sep 03, 2010
|
|
Reply 1In C# Langaugage, Microsoft has provided the facility of multi-cast delegate to implement the Observer Pattern. As Rajesh has mentioned there are sites which provides the implementation of same.
At the same time there is something you need to be aware off when using the multi-cast delegate. If the user has assigned, say two delegates and then assigns a null value, it will be treated as un-assigned and both previously assigned delegates will not execute. - Saurabh Saurabh Saxena, Sep 06, 2010
|
|
Reply 2In a way delegates and events can be used to implement observer pattern. You'll find some useful discussions here
http://stackoverflow.com/questions/32034/in-c-isnt-the-observer-pattern-already-implemented-using-events and here http://www.c-sharpcorner.com/UploadFile/fbulovic/ObserverNETEventFB12052005041517AM/ObserverNETEventFB.aspx Thanks. Rajesh Pillai, Sep 03, 2010
|