DEV Community

Cover image for Publisher Subscriber Design Pattern with C#
manoj
manoj

Posted on

2

Publisher Subscriber Design Pattern with C#

pub-sub

Publisher-Subscriber (pub-sub) is a design pattern that allows loose coupling between the application components.
Also the pattern is an implementation of event-driven architecture. For implementing this pattern we will mainly write two classes Publisher Class and Subscriber Class.

The major difference in Pub-Sub design is the event channel that publisher generates to notify changes to its subscriber without any knowledge of subscriber existence.

Realtime Examples:

  • Publisher class publishes an event ( like Youtube channels video notification ) for its' subscribers using an EventHandler.
  • Subscriber class receives the event ( like Youtube channel subscribers ) and handles it as it's needed.
  • EventHandler involved in this process of Publisher-Subscriber pattern to get notifications from Youtube Channel (Publisher) and send it to Channel subscribers.
  • Publisher class and Subscriber class doesn't have to know each other they both are connected to EventHandler.
  • Publisher will send the NotificationEvent to EventHandler and it will send the NotificationEvent to Subscribers.

Alt Text

Cheers!!

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
bazen profile image
Bazen

It would be good to have sample code since the title states C#

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay