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 6926949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:59:05+00:00 2026-05-27T10:59:05+00:00

I am making a network application. Here is the problem: I have a Messenger

  • 0

I am making a network application. Here is the problem:

I have a Messenger class. The Messenger has several module classes named ModuleA,B,C etc.
The messenger sends MessagePacks (to other Messengers). Each MessagePack has a module destination meaning once it reaches Messenger it is forwarded to the correct Module(A,B,C etc).

At the moment in order to forward to the correct module I’m using an if-else checking for a tag on MessagePack to decide where to forward.

What I would like to do is have MessagePack subclasses instead of using tags(tags are Strings).So TypeAMessage goes to ModuleA etc. The only way I can think to do that is having an instance of Messenger in the MessagePack and call a method like this: Messenger.fowardToModuleA(this); but it doesn’t make sense(and probably causes problems) to have an instance of Messenger on MessagePack.

Can anyone think of a way to complete the task I want without using the if-else checking for tag strings and preferably using MessagePack subclasses?

  • 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-05-27T10:59:05+00:00Added an answer on May 27, 2026 at 10:59 am

    An(other) option would be to let the Modules decide which MessagePack they accept and which not. So your Messenger would still contain/link to several Module classes, but just forward every incoming MessagePack towards all Modules like

    for ( Module module : modules ){
      if ( module.canHandle( messagePack ) ){
         module.handle( messagePack );
         //if messagePacks should only be handled by one module, break
      }
    }
    

    Whether or not those module’s use a String identifier on the messagepack, or only accept certain specific implementations of a messagepack interface is up to you. With this approach you have

    • a Messenger class which needs no adjustments when you add modules or messagepack types
    • one entry-point for all messages on a messenger
    • a module should only contain logic/knowledge for the type of messagepacks it can handle. So when adding a new messagepack, you only need to adjust the module which will handle this.

    Not sure whether this is an official design pattern with an official name, but that is how I would handle this

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

Sidebar

Related Questions

I am making a network application that has a chat function. On the chat
I am making a Client Server application for my Android phone. I have created
We have a .NET application which, on a certain server, keeps making various TCP
my application has a queue with outgoing network packets (A POJO with a ByteBuffer
I have an application which is making use of the RSACryptoServiceProvider to decrypt some
I have an ASP.Net Framework 4 web application making an interop call to a
Here's the scenario: I have a multi threaded java web application which is running
I have an application in C# .NET which has a MainForm and a few
I am making a network application where users can change channels and I want
I have an application which communicates over the local area network. However, I want

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.