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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:23:32+00:00 2026-06-06T05:23:32+00:00

This is the first time, I am involved in writing a complete client for

  • 0

This is the first time, I am involved in writing a complete client for an external server (I am very very new to design pattern).

This server provides couple of protocols to connect and send command e.g. REST, SOAP, and few more.

All of these protocols performs almost same set of actions, but it differes. I need to design and implement a complete client framework for it which will support all these protocols.

As understand and gone through couple of internet links, it seems to me to use an abstract factory pattern and interfaces for it.

my current thought for implementating it is as follows:

  1. Create a abstract factory class for Connection (ConnectionFactory). Based on the input, mentioning the protocol to use, the respective Connection object will be created. This abstract class will have an abstract method (processMessage). This method must be implemented in all the protocol’s connection class. This single method (processMessage) will take a arugument mentioning th type of request to execute. There is a separate request name for each protocol. How can I take care of it using constant?

  2. Define an interface for Request, Response and Client. All of the protocols will have their own Request, Response and Client class which will implement their respective interfaces.

Please provide me your valuable input about this design; please suggest me something better I can do it here.
I am still not able to finalize the directory structure, please help me for the same.

  • 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-06T05:23:34+00:00Added an answer on June 6, 2026 at 5:23 am

    If you are planning on defining a class hierarchy for the different protocols, try to avoid creating a parallel hierarchy for the data types (Request, Response, etc). This is often considered an anti-pattern and is referred to as a “parallel inheritance hierarchy”. Here’s an example question. The main drawback to this approach is having to maintain multiple parallel class hierarchies.

    Creating the Connection factory sounds reasonable. It should most likely return a class instance that has methods createMessage() for sending messages to the server and processMessage() for receiving messages from the server and the factory will plugin the ProtocolHandler explained next.

    As for the Request and Response you could define a ProtocolHandler member in the Connection class using a Strategy pattern, whereby each implementation would be a class that can handle, parse, marshal, etc the details of the respective protocol (REST, SOAP, etc). The Connection class processMessage() and createMessage() methods would use the ProtocolHandler class hierarchy.

    Here is some pseudo-code in c++, I havent compiled nor tested it, but I hope it gives you a good idea of what Im trying to explain.

    // Your factory will create the Connection instance and fill in the
    // corresponding ProtocolHandler concrete implementation instance
    
    class Connection
    {
    public:
        // Depending on what else you need for the Connection,
        // the constructors may be different
        Connection() : handler_(NULL) {}
        Connection(ProtocolHandler *handler) : handler_(handler) {}
    
        inline void setProtocolHandler(ProtocolHandler *handler) {handler_ = handler;}
        inline ProtocolHandler *getProtocolHandler() {return handler_;}
    
        void processMessage(const string &msg) {
            handler_->decode(msg);
            // any extra logic here
        }
    
        string createMessage() {
            // any extra logic here
            return handler_->encode();
        }
    
        // Put the rest of your connection stuff here
    
    private:
        ProtocolHandler *handler_;
    
    };
    
    // Notice that Im handling the protocol msg buffers in a std::string, this
    // may or may not work for you, replace accordingly depending on your needs
    
    class ProtocolHandler
    {
    public:
    
        // abstract methods
        // name these accordingly as handle, parse, marshal, etc
        virtual string encode() = 0;
        virtual void decode(const string &msg) = 0;
    
        // Other methods you may need here
    };
    
    class RestProtocolHandler : public ProtocolHandler
    {
    public:
        virtual string encode() { /* your rest msg encode impl here */ }
        virtual void decode(const string &msg) { /* your rest msg decode impl here */ }
    
        // Other methods and/or attributes you may need here
    };
    
    // More concrete ProtocolHandler implementations here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The first time this loop iterates works well but after I press the char
This is my first time comparing dates in Objective-C. I've been searching the web
this is my first time playing with recursive functions, and this function that I
This is my first time posting to Stack Overflow. I'm trying to build a
this is my first time trying to use java for backend web systems. I
this is my first time in using recaptcha on my website. I'm using PHP
This is my first time posting on stackoverflow so bear with me. I decided
This is my first time using Eclipse 3.3.2 to make an application in Java.
This is my first time using JFileChooser in Java and I'm currently attempting to
This is my first time programming and I'm struggling to understand what should be

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.