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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:41:34+00:00 2026-06-13T18:41:34+00:00

I am creating a instant chat application using RMI. The server sends through certain

  • 0

I am creating a instant chat application using RMI. The server sends through certain objects which I need the client to handle.
For example the server will send a JoinedGroupOperation class. In my client application I need to recognise the class and let my handler take over (HandleJoinedGroupOperation). This class will do a bunch of stuff on the client side.

My question is how can I handle classes that come from the server so I don’t need to do any if statements? ie

if(server.getResponse() instanceof JoinedGroupOperation){
    HandleJoinedGroupOperation handle = new HandleJoinedGroupOperation();
    handle.foo();
}
  • 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-13T18:41:35+00:00Added an answer on June 13, 2026 at 6:41 pm

    One of the possible option in your case is to use chain of responsibility design patern.
    You should create some abstraction of your possible handlers(like HandleJoinedGroupOperation), then link those handlers(preferebly at start time). As a example, create an interface

     interface OperationHandler {
         void handle(Operation op);
    }
    

    where Operation is also a basic type for all possible operations. This type(Operation) can contain a field of enum type OperationType:

    enum OperationType {
    ...
    }
    

    Then in the concrete handlers you can simply check this field(although it will contain if statement, but those statements will be encapsulated in each specific handler)

    As a simple example, here is a default implementation of a handler

    class SimpleHandler implements OperationHandler {
     private OperationHandler next;
    
     public void handle(Operation op) {
         if (op.getType() == OperationType.SOMEYOURTYPE) {
            //do some stuff
         } else {
            next.handle(op);
         }
     }
    }
    

    In this case your server.getResponse() method simply will return basic type of Operation hierarchy

    Also read the article to get more information

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

Sidebar

Related Questions

At the moment I am creating a client server console application in c++. With
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
I am creating an Instant Messenger for android using asmack. I have started a
Creating a server-side socket will fail if I'm trying to use the same port
Creating a simple RPG game, first time using XNA. Trying to get my character
It needs to create instant messenger application. Background thread should work under lock screen
I am attempting to create Domino DateTime objects in arbitrary time zones using the
Creating the closure is easy but using it is confusing for me. Here is
Creating a rating system and the info is not being transmitted through my $_GET
When creating apps that interface on various TCP protocols (apart from HTTP), we need

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.