Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

design question - logic and interface separation

Posted on 2012-04-03
9
Medium Priority
?
421 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Assisted Solution

by:ambience
ambience earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

721 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