Observer Pattern in .NET

Introduction

I have previously written a few posts about delegates, .NET Events, Events Args to show that similar to real-world events, we can use this concept in our code and how useful they are in certain scenarios. This post will see that those types are a good candidate for implementing the observer pattern without doing anything extra. We will learn some terminologies and see a working example as well.

If you are new to .NET Events, I will suggest reading my previous posts on the topic, and then discussed in this post will be easier to follow. So let's talk about observer pattern:

Delegates: Can’t Deal With Them, Can’t Live Without Them

Introduction

There is a famous quote by Jim Henson: “If you can’t beat themJoin them”.

It’s possible to write code for years without deliberately using delegates. I say “deliberately” because we may have used them without realizing it. Knowing what these types represent makes reading code easier. Knowing how to use them adds some useful tools to our developer toolbox. So instead of ignoring them, why not learn them. In this post, I will show you how you can get started with delegates and their use cases, which will encourage you to use them more in your code.