Solved

design question - logic and interface separation

Posted on 2012-04-03
9
397 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
[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
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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
show out valin of json for debugging in visaul c++ 1 54
SSRS troubles 4 106
Infrastructure development vs software development 3 107
Bitwise and to sum elements 2 54
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

752 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