Skip to content

AhmedTarekHasan/ObserverDesignPatternInDotNetCSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Observer Design Pattern in .NET C#

Learn about the Observer Design Pattern in .NET C# with some enhancements.


The Observer Design Pattern is one of the most important and commonly used design patterns, and this is for a reason.


First, let’s check the formal definition of the Observer Design Pattern.


As per Microsoft’s documentation: The observer design pattern enables a subscriber to register with and receive notifications from a provider. It is suitable for any scenario that requires push-based notification. The pattern defines a provider (also known as a subject or an observable) and zero, one, or more observers. Observers register with the provider, and whenever a predefined condition, event, or state change occurs, the provider automatically notifies all observers by calling one of their methods. In this method call, the provider can also provide current state information to observers. In .NET, the observer design pattern is applied by implementing the generic System.IObservable and System.IObserver interfaces. The generic type parameter represents the type that provides notification information.


So, from the definition above, we can understand the following:
1. We have two parties or modules.
2. The module which has some stream of information to provide. This module is called Provider (as it provides information), or Subject (as it subjects information to outside world), or Observable (as it could be observed by outside world).
3. The module which is interested into a stream of information coming from somewhere else. This module is called Observer (as it observes information).


If you are interested into reading more about this topic, you can read the rest of the article.


If you want to support me:

▶ Subscribe to Medium using my referral link
▶ Subscribe to Medium Newsletter
▶ Subscribe to LinkedIn Newsletter
▶ Follow me on Medium
▶ Follow me on Twitter
▶ Follow me on LinkedIn


Authors: