observer pattern vs delegates and events?

I am just starting to get a handle on design patterns and C#.

Does anyone have any advice as to when use the observer pattern over Delegates and/or actually registering a .NET event.

My guess would be that a simple ICustomObserver interface and textbook examples of the pattern would have less overhead than the formal .NET approach

Delegates seem to become much more useful when you want to pass a type safe function pointer to some object's method. Delegates are also used in events (that is kinda why I am bringing all 3 up). But my impression is that I should think of delegates as a type of parameter (or variable) that stores a method address. Is that right

Events seem to be more like the observer pattern. But they are derived from system.object (at least), that must cost something. I am thinking that maybe I use events in only the GUI layers and not any of the lower layers Has anyone tried this

Sorry to be all over the place with these questions, but i think they relate.......

Thanks for all response!

Bob



Answer this question

observer pattern vs delegates and events?

  • Bassam Adil

    I would only use the 'Observer' pattern in a language where you do not have things like events/delegates.
    You can see the usage of delegates as an alternative way of implementing the Observer pattern.

    Why would you choose to not use events in the Non GUI layers What would be the advantage


  • observer pattern vs delegates and events?