Solved

design question - logic and interface separation

Posted on 2012-04-03
9
375 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now