Solved

Subject, Registrar, 4 Listener Revisited - Design Guidance Requested

Posted on 2008-10-11
3
185 Views
Last Modified: 2011-10-19
See attached.

I  tried to use expert help found here: "http://www.experts-exchange.com/Programming/Languages/CPP/Q_23729314.html"  to build on my design.



Listeners 1 will extract the words from an 21S message that is important to Listener 1 and in doing so build an 2S and 3S  message.   2S and 3S  are messages Listener 1 understands.   For example:  Words 1,2,4,5,and 6 from a 21S  message gets copied into an 2S message.   Words 1,3,7 and 9 from a 21S message gets copied
into an 3S message.

Listeners 2 will extract the words from an 21S  message that is important to Listener 2 and in doing so build an 4S and 7S message.   4S and 7S are messages Listener 2 understands.  Since the 4S and 7S messages aren't shown in the attached I'll ignore the words numbers.

In my current design each Listener gets an 21S message and this is  quickly becoming a maintenance nightmare.  I'd like to place a message handler/translator in the middle.  The message translators job is to translate an 21S message into the appropriate format the Listener understands.  The translator will then give the Listener an 2S,3S(Listener1) or 4S,7S(Listener2) message.    I believe that a generic solution exists that will accomplish the goal of the translator but I'm not sure how to do this.   I'm not sure how to structure the translator and in doing so exploit C++ template facilities to accomplish my objective.  


if-design.doc
0
Comment
Question by:forums_mp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 22702924
Something like below (crude example) ?


>> I believe that a generic solution exists

I think what you're referring to are design patterns. The adapter and mediator patterns come to mind :

        http://en.wikipedia.org/wiki/Adapter_pattern
        http://en.wikipedia.org/wiki/Mediator_pattern
class Msg {
};
 
 
 
 
class Listener {
  public :
    virtual void processMsg(Msg &msg) = 0;
};
 
class ListenerA : public Listener {
  public :
    virtual void processMsg(Msg &msg) {
      // do something with the message
    }
};
 
class ListenerB : public Listener {
  public :
    virtual void processMsg(Msg &msg) {
      // do something with the message
    }
};
 
 
 
 
class Dispatcher {
  private :
    std::vector<Listener*> listeners;
 
  public :
    void addListener(Listener &listener) {
      listeners.push_back(&listener);
    }
    void processMsg(Msg &msg) {
      // split up the s21 message ... then :
      Msg s2, s3, s4, s7;
      listeners[0]->processMsg(s2);
      listeners[0]->processMsg(s3);
      listeners[1]->processMsg(s4);
      listeners[1]->processMsg(s7);
    }
};
 
Dispatcher dispatcher;
Listener1 listener1;
Listener2 listener2;
dispatcher.addListener(listener1);
dispatcher.addListener(listener2);
 
 
 
 
 
class Sender {
  public :
    void send() {
      Msg s21;
      dispatcher.processMsg(s21);
    }
};

Open in new window

0
 

Author Comment

by:forums_mp
ID: 22837431
I paid a coder $35/hour for 6 hours of work on guru.com for a solution.  With all due respect I'm not posting my solution.   Once again, I  could assure you infinity's solution is not worth 500 points but if you feel that his solution warrants 500 points then by all means close the issue.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java inner class, for the sole use of parameter passing 21 78
thread-safe code in c++ 2 122
basic hardware to learn oop advanced design patterns 3 110
I could not build boost code, 10 107
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question