<p>After reading the Head First Design Patterns book and using a number of other design patterns, I'm trying to understand the Observer pattern. Isn't this already implemented using Events in the .NET Framework?</p>

[{'answer_id': 32036, 'author': 'Sander', 'author_id': 2928, 'author_profile': 'https://Stackoverflow.com/users/2928', 'pm_score': 6, 'selected': True, 'text': '<p>Yes, it is. The observer pattern is also called the publish/subscribe pattern, which is exactly what events allow you to do.</p>\n'}, {'answer_id': 32040, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 2, 'selected': False, 'text': "<p>That's right, events are an implementation of the observer pattern.  I have read discussions , though, of people who still write their own, to give them either more flexibility, or maybe just to avoid the event-raising syntax.</p>\n"}, {'answer_id': 32082, 'author': 'Dinah', 'author_id': 356, 'author_profile': 'https://Stackoverflow.com/users/356', 'pm_score': 3, 'selected': False, 'text': "<p>Yes, it's identical.</p>\n\n<p>A note: if you really want to understand events, I recommend learning the observer pattern and implementing it yourself a for a while. Once you fully understand it, stop doing it yourself and use the professional and well-documented implementation unless you have a real need to do otherwise.</p>\n"}, {'answer_id': 32094, 'author': 'flipdoubt', 'author_id': 470, 'author_profile': 'https://Stackoverflow.com/users/470', 'pm_score': 5, 'selected': False, 'text': '<p>I would say yes, it was Anders Heljsberg\'s intent to make the observer pattern a first-class language feature with events in C#, based on his experience with Delphi. Anders makes this and other design intentions clear in an excellent interview on <a href="http://www.se-radio.net/podcast/2008-05/episode-97-interview-anders-hejlsberg" rel="noreferrer">Software Engineering Radio</a>.</p>\n'}, {'answer_id': 32110, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 0, 'selected': False, 'text': '<p>Most modern languages have native support for some of the design patterns. It has been argued that languages are better the more patterns they support natively without the need to implement them explicitly, and that Lisp is excellent in this regard. Jeff had <a href="http://www.codinghorror.com/blog/archives/000308.html" rel="nofollow noreferrer">something to say</a> about that, too.</p>\n'}, {'answer_id': 100921, 'author': 'Hace', 'author_id': 18703, 'author_profile': 'https://Stackoverflow.com/users/18703', 'pm_score': 2, 'selected': False, 'text': '<p>Yes, but programming the observer pattern explicitly and thus not using delegates and events can result in easier debugging of your code.</p>\n\n<p>Consider the difference:</p>\n\n<pre><code>public void NotifyObservers()\n{\n    foreach(Product product in ProductList)\n    {\n        if (product is IProductObserver)\n        {\n               product.Update(this)\n        }\n    }\n}\n</code></pre>\n\n<p>Here it is very clear what products in the list get notified of a change. While debugging you can inspect the ProductList...</p>\n\n<p>With using delegates and events it can be more cumbersome to find out how many "delegates" were actually "subscribed" to handle the event.</p>\n'}, {'answer_id': 30501340, 'author': 'Uchiha Madara', 'author_id': 1240317, 'author_profile': 'https://Stackoverflow.com/users/1240317', 'pm_score': -1, 'selected': False, 'text': '<p>No, they achieve the same intent, however they are different.\nI would say that the Observer pattern is quite a hack of over design to achieve something you could have achieved easily with functional programming, and that .NET events uses functional programming to achieve the same goal.</p>\n'}, {'answer_id': 31158776, 'author': 'Anestis Kivranoglou', 'author_id': 850980, 'author_profile': 'https://Stackoverflow.com/users/850980', 'pm_score': 0, 'selected': False, 'text': '<p><strong>Microsoft</strong> Itself States that using events and delegates is the c# way of applying the Observer Pattern.\nUsing some basic naming conventions for events and delegates they named their own pattern as <strong>"Event Pattern"</strong> which does exactly the same thing providing some extra advantages over the classic <strong>Observer Pattern</strong>.</p>\n\n<p><strong>"Event Pattern"</strong> is described in the MSDN Library inside the "<strong>Exploring the Observer Design Pattern</strong>" Article.</p>\n\n<p><a href="https://msdn.microsoft.com/en-us/library/ee817669.aspx#observerpattern_topic3b" rel="nofollow">Reference MSDN Article</a></p>\n\n<blockquote>\n  <p><em>Based on events and delegates, the FCL uses the Observer pattern quite extensively. The designers of the FCL fully realized the inherent power of this pattern, applying it to both user interface and non-UI specific features throughout the Framework. This use, however, is a slight variation on the base Observer pattern, which the Framework team has termed the Event Pattern. In general, this pattern is expressed as formal naming conventions for delegates, events, and related methods involved in the event notification process. Microsoft recommends that all applications and frameworks that utilize events and delegates adopt this pattern, although there is no enforcement in the CLR or standard compiler</em></p>\n  \n  <p><em>Based on this examination of the Observer pattern, it should be evident that this pattern provides an ideal mechanism to ensure crisp boundaries between objects in an application, regardless of their function (UI or otherwise). Although fairly simple to implement via callbacks (using the IObserver and IObservable interfaces), the CLR concepts of delegates and events handle the majority of the "heavy lifting," as well as decreasing the level of coupling between subject and observer.</em></p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/32034', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2993/']