Lecture thumbnail 0:03 / 2:10 So in this section of the course, we’re going to talk about the observer design pattern.

So what is the motivation behind using the observer design pattern?

Well, it’s actually quite simple.

We need to be notified or informed when certain things happen in our system.

So, for example, you have an object in the system and that object’s property changes to something.

Or maybe the object simply does something and you want to be informed about it, or maybe some sort

of external event occurs.

Now, whatever it is that you want to be informed about, you basically want to listen to events and

events are simply encapsulated information about what just happened and you want to be notified about

these things when they occur.

And this is kind of built into the C-sharp programming language.

So the language designers basically decided that they would bake in the observer design pattern using

the event keyword.

But that’s not the only thing which is available in the C programming language.

So for example, we have interfaces like I observable and I observer.

Now you might be thinking, hold on, these are reactive extensions interfaces.

They’re in a separate NuGet package.

Well, not really.

Even though reactive extensions are in fact in a separate NuGet package, I observable of t and I observer

of t are in fact in the system namespace.

They’re in the system assembly, so they are baked into right a right into dotnet itself.

They’re not in some external package.

So why are they there and what are they for?

That’s what we’re going to discuss.

In addition, we’ll take a look at interfaces such as I notify property changing and I notify property

changed.

These interfaces are used for notifications on properties, as their name suggests.

And also we’ll discuss the observer design pattern when applied to sets or sequences of values rather

than individual values.

And we’re going to take a look at things like binding lists of T or observable collection.

But the observer design pattern itself is fairly simple.

So we have this idea of an observer, which is an object that wishes to be informed about events happening

somewhere in the system.

And typically the observer would subscribe to monitor those events and to receive notifications about

those events and on the other hand, we have the entity that’s generating those events, which is typically

called an observable.

Stop Play Play Play Play Play Play Play Start Play information alert