Solved

design question - logic and interface separation

Posted on 2012-04-03
9
388 Views
Last Modified: 2012-04-04
Hi Experts,

I have a fairly large existing app that runs on a sort of event simulation.  It's an MFC app that has the mainframe currently responding to events in the business logic code.  Since now I'm interested in making a more clear separation between the business logic and the interface, I'm wondering what the best way there is about sending the messages.  This is my current idea:

Whatever messages handlers exist in the mainframe should be pulled into another class.  Let's call it my controller.  Since the messages are coming in on my event queue in mainframe (from other worker threads running), my controller class seems to need its own event queue that I can PostMessage to.  Is this correct?  Should I make a CWnd-derived class to replace the mainframe so that I get an event queue for free?  (this seems very wrong to me).  My ultimate goal is to remove all GUI from the existing app and communicate all of the GUI items through a socket interface where multiple machines can get the interface update messages through the controller class and do their own interpretation of what the GUI should show (for different kinds of machines).....

Thanks for your help!
Mike
0
Comment
Question by:thready
  • 5
  • 4
9 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
ID: 37802482
Im not sure I fully understood the current design, especially the role of mainframe, to make a good suggestion. One thing is somewhat clear though, moving to a distributed architecture would inevitably require you to abstract away the specifics of PostMessage and event queues.

Thinking of multiple machines it makes sense to envision the architecture as consisting of publishers of events (worker threads), subscribers of events (GUI) and the routing fabric that deals with the specifics of event dispatching. It can further be broken down broadly into an open broadcast over multicast or a registry based design whereby each observer/subscriber registers with the routing fabric to receive notifications.

I would suggest that you refactor your code along these lines. For example I would consider having a NotificationCenter component that would hold all the necessary stuff to route messages either on the same machine or across multiple. Then each event would be represented by a Notifcation object (preferably serialize for easier transmission over the wire).

Any publisher would grab hold of the NoticationCenter (perhaps a singleton) and "post" a notification. The NotificationCenter will have a list of dispatchers, for example a LocalNotificationDispatcher and a RemoteNotificationDispatcher. The Local as you may guess would be implement the Observer pattern and subsribers will observe it for notifications. The Remote... will flatten the notification and send over the wire. A NotificationCenter on another machine can pick it up and dispatch it through its LocalDispatcher.

Thats pretty much the basic building blocks that can be fattened later on like supporting intelligent routing by having the subscribers declare the kind of events that they are interested in.

Needless to mention but the controller (in your comments) would be a subscriber or it could even be the MainFrame. In any way thats a separate area of design.

I used the terminology that POCO uses http://pocoproject.org/docs/Poco.NotificationCenter.html and I also suggest to have a look at the samples.
0
 
LVL 22

Expert Comment

by:ambience
ID: 37802508
0
 
LVL 1

Author Comment

by:thready
ID: 37802856
Beautiful!  I was even planning on using Poco with the TcpServer to do multicasting!

I will wait for any more awesome comments, but so far you have all the deserved points!  Thanks a lot for the help!  :)
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 22

Assisted Solution

by:ambience
ambience earned 500 total points
ID: 37805396
BTW, I should have mentioned that my idea of NotificationCenter isn't strictly the same as the stock NC in POCO. I hope I explained my thoughts well enough and this is obvious but just in case. POCO would be a good starting point.
0
 
LVL 1

Author Comment

by:thready
ID: 37806189
Are you saying I should not use the NotificationCenter from POCO because it has weaknesses or lacks things from the architecture you described?
0
 
LVL 1

Author Closing Comment

by:thready
ID: 37806197
I get it.  Thank you very much for your excellent help!
0
 
LVL 1

Author Comment

by:thready
ID: 37806623
I think I need to just create my own classes.  Not get tied down to try to fit what Poco does.
0
 
LVL 22

Expert Comment

by:ambience
ID: 37806756
Yes that would be preferable, though its always inspirational taking a look at something well designed for a specific purpose.
0
 
LVL 1

Author Comment

by:thready
ID: 37806757
Thanks!  I invite you to my next question in case you're interested:  http://www.experts-exchange.com/Programming/Languages/CPP/Q_27662268.html
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

830 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