Solved

design question - logic and interface separation

Posted on 2012-04-03
9
379 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

930 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

10 Experts available now in Live!

Get 1:1 Help Now