Skip to main content
deleted 37 characters in body
Source Link
Marjan Venema
  • 8.2k
  • 3
  • 34
  • 36

The delegate pattern, as I understand you call it, is know as the event handler mechanism in other languages. I think it was C# that introduced the term "delegate", for meexample Delphi. As such it simply is an implementation of the observer pattern with a major restriction: only one listener at a time.

The disadvantage of event handlers or delegates is obvious: only one observer.

The advantage is not so obvious: performance. With an observer pattern you can add many observers. When an event occurs that the observers need to be notified about, you will need to enumerate the observers and send a notification to each. This can quickly bog down any observed instance, especially when the number of events that require notification is significant as well.

The delegate pattern, as you call it, is know as the event handler mechanism in other languages. I think it was C# that introduced the term "delegate" for me. As such it simply is an implementation of the observer pattern with a major restriction: only one listener at a time.

The disadvantage of event handlers or delegates is obvious: only one observer.

The advantage is not so obvious: performance. With an observer pattern you can add many observers. When an event occurs that the observers need to be notified about, you will need to enumerate the observers and send a notification to each. This can quickly bog down any observed instance, especially when the number of events that require notification is significant as well.

The delegate pattern, as I understand you, is know as the event handler mechanism in other languages, for example Delphi. As such it simply is an implementation of the observer pattern with a major restriction: only one listener at a time.

The disadvantage of event handlers or delegates is obvious: only one observer.

The advantage is not so obvious: performance. With an observer pattern you can add many observers. When an event occurs that the observers need to be notified about, you will need to enumerate the observers and send a notification to each. This can quickly bog down any observed instance, especially when the number of events that require notification is significant as well.

Source Link
Marjan Venema
  • 8.2k
  • 3
  • 34
  • 36

The delegate pattern, as you call it, is know as the event handler mechanism in other languages. I think it was C# that introduced the term "delegate" for me. As such it simply is an implementation of the observer pattern with a major restriction: only one listener at a time.

The disadvantage of event handlers or delegates is obvious: only one observer.

The advantage is not so obvious: performance. With an observer pattern you can add many observers. When an event occurs that the observers need to be notified about, you will need to enumerate the observers and send a notification to each. This can quickly bog down any observed instance, especially when the number of events that require notification is significant as well.