Whilst learning events and delegates I can’t help but think about the Observer design pattern.
I’m sort of novice level with both C# and design patterns. When using events and delegates to lets say, firing an event from a child form and being picked up by the parent, is that the Observer design pattern?
What other design patters are events and delegates used in?
I’d be interested to know about other ‘things’ (sorry for my lack of terminology) in .NET are based on common design patterns, such as those from the Gang of Four.
I think it’s easier to understand code examples and explanations with such topics if you can relate it to a pattern. Personally anyway.
Thanks.
Yes. Events are basically a langauge-specific implementaiton of the observer design pattern. It was deemed useful enough to build directly into the language in C#.
Many design patterns can be written using delegates in C# – But that’s more of an implementation detail than the pattern itself. For example, the visitor pattern and the command pattern can be implemented (quite elegantly) via delegates.