Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:34:35+00:00 2026-06-05T08:34:35+00:00

I have the following scenario: I have a QueueReader class that will be reading

  • 0

I have the following scenario:

I have a QueueReader class that will be reading messages from a queue. I also have some Senders like EmailSender and SMSSender, that will send these messages to clients using Email or SMS respectively. In the future more Senders can be added.

I can think of two ways of doing this and I am not sure which would be more beneficial.

Factory Pattern:

I can have a SenderManager that will use a SenderFactory to create the appropriate sender and then call its Send() method.

So the QueueReader upon reading a message will call the SenderManager’s Send() which will do the following:

IMySender sender = SenderFactory.CreateSender()
sender.Send()

//I have the information to create the proper Dispatcher in the 
//factory based upon the message but I have omitted it for brevity.

So, now if I have to add a new sender, I won’t have to change the QueueReader or the SenderManager. I will just add the new Sender and modify the SenderFactory.

Observer Pattern
In contrast to the above, I can have the QueueReader class implement an Event for NewMessage. Then have all my Senders subscribe to this event. The Sender will have access to the information that was in the Factory above to know if the message is for them.

The benefit of this would be any new Sender will simply have to subscribe to the event.

Now that I have written all of this down, I think the Observer Pattern is the cleaner approach…

However, if anyone has any insight or suggestion, please do share.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:34:37+00:00Added an answer on June 5, 2026 at 8:34 am

    I would use an hybrid approach:

    SenderManager (The observer) would listen to the incoming messages and pick the right sender (or ask the SenderFactory to create one if needed). This has 2 benefits:

    First, you have control over which sender you pick (You don’t need to expose the SenderManager class) avoiding attack of type ManInTheMiddle. This is particularly important if you are going to expose an API for other developers to implement their own senders.

    Second, you can implement a sort of Garbage Collector and dispose of the sender that are no longer needed, instead of having multiple senders that are instantiated and monitoring your stream for nothing.

    You will need some kind of registration function to register the senders against the SenderManger.

    If you use an ObserverPattern, don’t forget to implement a default sender (can be a log system) in order to handle the unwanted messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario : I’m pushing 100 messages to a queue shared
I have he following scenario: Got an HTML template file that will be used
I have the following scenario: Entities are loaded from the database. One of them
I have the following scenario, class foo { ... private: char *_test; }; void
I have the following scenario: User X logs in to the application from location
I have this following scenario namespace A { //... class A { public: static
I have the following scenario that may warrant storing data in a conroller member
I have the following scenario: class my_base { ... } class my_derived : public
I have the following scenario (C#, WinForms). I have some kind of project file
I have following scenario. Some people use approach 1 and some use approach 2.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.