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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:07:42+00:00 2026-05-21T05:07:42+00:00

I am writing a Java client that communicates with a remote server via HTTP/XML.

  • 0

I am writing a Java client that communicates with a remote server via HTTP/XML.

Server sends commands to my client in XML format, like this:

<command>
<name>C1</name>
<param>
.....
</param>
</command>

There is about 10 or more different commands (C1, C2, …), each of them has different set of params.

My client will process the command, then response server with a execute result, looks like this:

<C1>
<code>200</code>
<desc>xxx</desc>
</C1>

I am only familiar with C, but very new to Java and OOP,

so, my question is simple, how to design the following logic gracefully in a OOP way?

1.Convert the XML string to an XML Object
2.Find correspoding executor based on ‘name’ element of the XML, and parse the params
3.Execute the command along with the params
4.Convert the result to an XML Object
5.Convert the XML Object to an XML string

Is this a good design?

1.Define an abstract base class and many sub-classes for each command, which include the following method:

void parseCommand(MyXMLObject obj);
void execute();
MyXMLObject generateResult();

or just a simple method:

MyXMLObject execute(MyXMLObject obj);

and these fields:

String mCommandName;
int mRetCode;
String mRetDesc;

2.Then define a factory class to return an instance of one of the sub-classes based on the XML Object.

3.The logic part code:

MyXMLObject obj = MyXMLUtil.getXMLObject(XMLString);
MyCommand command = MyCommandFactory.getCommand(obj);
MyXMLObject retObj = command.execute();
String retStr = MyXMLUtil.getString(retObj);
...//network operation
  • 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-21T05:07:43+00:00Added an answer on May 21, 2026 at 5:07 am

    Generally speaking, it is a good design (you probably need more interfaces and such, and there are various refinements).

    The greater problem is that this is, in many ways, a reinvention of the wheel. There are numerous frameworks that handle mapping from POJOs (java objects) to structured textual formats (such as XML or JSON). On top of that, there are many general implementations of command frameworks. It might be worth investigating available options before you provide your own implementation.

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

Sidebar

Related Questions

I am writing a C# client that calls a web service written in Java
I am writing a client-side Swing application (graphical font designer) on Java 5 .
I am writing a Java utility that helps me to generate loads of data
I'm writing a Java application that runs on Linux (using Sun's JDK). It keeps
I'm writing a Java Tree in which tree nodes could have children that take
I am writing a java program that needs a file open dialog. The file
I'm in Eclipse writing Java. I come from Visual Studio with Resharper writing C#.
Please suggest some good resources to start writing Java Web services.
For various reasons calling System.exit is frowned upon when writing Java Applications , so
I'm writing a Java game and I want to implement a power meter for

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.