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

  • Home
  • SEARCH
  • 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 838137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:15:15+00:00 2026-05-15T05:15:15+00:00

May be i am not able to express my doubt properly in this question

  • 0

May be i am not able to express my doubt properly in this question but still i will try. Basically i created a simple socket based chat program and everything works fine. But i think i have made many patches in it from the design point of view.

I have used ObjectInputStream and ObjectOutputStreams in my program. The question i want to ask is how do i identify the different type of data that i send across the network? say if it is simple String type object i directly add to List<String> chatMessages. Now if want to ban certain users i created an another class :-

public class User{
    private String name;
    private String id;
    //getters and setters
}

This User class means no importance to me till now but i only created it to properly identify the action. Thus if i receive an instanceOf User i can be sure that some user is to be banned. That way i dont have to hardcode strings. I mean first i thought of sending something like "Banned User :" + userName and then i used to check if string startsWith “Banned User :” then i take some action :p. I’ve created a User class but it means no importance to me in my program.

I want to know whether directly sending strings is good way or create a class for every action that is good. If i am not clear please let me know. If i have hundreds of action do i have to create hundreds of classes so i can check via instanceOf? Say now if i plan to create a BUZZ like facility that is available in yahoo messenger. Should i again create an another class named BUZZ? so it can be identified easily?

  • 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-15T05:15:16+00:00Added an answer on May 15, 2026 at 5:15 am

    Why not send Action objects across the wire ? You can then subclass these Action objects into (say):

    1. BanUserAction
    2. RecordChat
    3. AddUser

    etc. and each object instance contains the data required e.g. BanUser contains the name of the user to be banned.

    You wouldn’t need to use instanceof since each object would implement a common .act() method. You can then call that method, and you won’t have to care which object has been passed to you, since the object itself will take care of what to do (this is a core tenet of OO programming – tell objects to do things for you).

    Note that the act() method may require some context passed into it e.g. a reference to the containing chat service.

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

Sidebar

Related Questions

Okay, this may be a dumb question, but I've not been able to find
This may not be the correct way to use controllers, but I did notice
It may not be a pure programming question but I'm looking for information about
This may not really sound hard to do but it is currently killing me.
My question may not make sense but I have valid reason. We use .net
One may not always know the Type of an object at compile-time, but may
It may not be best practice but are there ways of removing unsused classes
The title may not really explain what I'm really trying to get at, couldn't
I have a User class which may or may not have an associated Department.
I want to let users specify a date that may or may not include

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.