C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with helper classes

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Tim Woodburn
Guest





PostPosted: Thu Oct 21, 2004 7:41 pm    Post subject: Help with helper classes Reply with quote



I have been looking for an example of helper classes.

The problem I have is that I want to send messages between different
classes.

My MFC application has a tree of objects on a splitter window, a flex
grid in another and a map in another. I am dragging an icon from the
tree over the map and logging the position where the left mouse button
is released. I want to send the map that position so it can display
the icon in the appropriate place. I also want to update the list in
the flexgrid etc. When I click on an entry on the flexgrid, I want
the map to highlight the target.

<End platform specific detail>

So my question is, how are helper classes defined?

A colleague showed me some UML where the flexgrid, map and tree
classes were aggregates of a GUI class. Each of the aggregates has a
pointer to the GUI class which is stored when the class is
instantiated by the constructor.

He explained that I would call a method in the GUI class from one of
the aggregates and the GUI method would route the messages to the
appropriate aggregates.

When I was shown this on paper, I understood the concept.
Unfortunately I have not been able to translate this into code.

Could someone show me a simple example (unrelated to the above!) of a
helper class with aggregated classes or point me to a suitable
tutorial? Or is there better way of doing this?

Thank you

Tim

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Michael Kurz
Guest





PostPosted: Sat Oct 23, 2004 2:25 pm    Post subject: Re: Help with helper classes Reply with quote




"Tim Woodburn" <tim (AT) robotcrazy (DOT) com> schrieb im Newsbeitrag
news:56aa5822.0410210338.5712811f (AT) posting (DOT) google.com...
Quote:
I have been looking for an example of helper classes.

The problem I have is that I want to send messages between different
classes.

My MFC application has a tree of objects on a splitter window, a flex
grid in another and a map in another. I am dragging an icon from the
tree over the map and logging the position where the left mouse button
is released. I want to send the map that position so it can display
the icon in the appropriate place. I also want to update the list in
the flexgrid etc. When I click on an entry on the flexgrid, I want
the map to highlight the target.

End platform specific detail

So my question is, how are helper classes defined?


I would look at the observer pattern.

Suggestion:
-Introduce a kind of DragNDrop Manager (typically a Singleton)
In the term of the observer pattern this Manager should be implement a kind
of "Observable" Interface,
which allows others (kind of clients) to register a callback for specific
events:
e.g something like: onIconDroppedNotification

So if an Icon is dropped, the DragNDrop manager will notify all observers
(which are registered).


In general the observer pattern is often very usefuly (specially within GUI
applications) to reduce dependencies.


Regards
Michael





[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Jeff Flinn
Guest





PostPosted: Sun Oct 24, 2004 4:10 am    Post subject: Re: Help with helper classes Reply with quote




"Tim Woodburn" <tim (AT) robotcrazy (DOT) com> wrote

Quote:
I have been looking for an example of helper classes.

The problem I have is that I want to send messages between different
classes.

My MFC application has a tree of objects on a splitter window, a flex
grid in another and a map in another. I am dragging an icon from the
tree over the map and logging the position where the left mouse button
is released. I want to send the map that position so it can display
the icon in the appropriate place. I also want to update the list in
the flexgrid etc. When I click on an entry on the flexgrid, I want
the map to highlight the target.

End platform specific detail

So my question is, how are helper classes defined?

A colleague showed me some UML where the flexgrid, map and tree
classes were aggregates of a GUI class. Each of the aggregates has a
pointer to the GUI class which is stored when the class is
instantiated by the constructor.

He explained that I would call a method in the GUI class from one of
the aggregates and the GUI method would route the messages to the
appropriate aggregates.

When I was shown this on paper, I understood the concept.
Unfortunately I have not been able to translate this into code.

Could someone show me a simple example (unrelated to the above!) of a
helper class with aggregated classes or point me to a suitable
tutorial? Or is there better way of doing this?

See the boost signal library at: http://www.boost.org/doc/html/signals.html

Jeff F



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Tim Woodburn
Guest





PostPosted: Wed Oct 27, 2004 12:59 am    Post subject: Re: Help with helper classes Reply with quote

Thanks to Jeff and Michael for their replies.

For the benefit of google I have found the following:

An example of a simple implementation of the observer pattern from the
code project "Implementing a Subject/Observer pattern with templates
"
http://bonxedes.notlong.com


An article which was exactly what I was looking for from Code Project
"Adding Behavior to Classes, Part I - An Introduction"
http://kaiwogne.notlong.com

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Balog Pal
Guest





PostPosted: Wed Oct 27, 2004 1:00 am    Post subject: Re: Help with helper classes Reply with quote

"Tim Woodburn" <tim (AT) robotcrazy (DOT) com> wrote


Quote:
The problem I have is that I want to send messages between different
classes.

To that you just need to find the class, then call the method. Smile Or yo can
use a mediator -- on windows the system is already in place, post a message,
then it gets dispatched...

Quote:
My MFC application has a tree of objects on a splitter window, a flex
grid in another and a map in another. I am dragging an icon from the
tree over the map and logging the position where the left mouse button
is released. I want to send the map that position so it can display
the icon in the appropriate place. I also want to update the list in
the flexgrid etc. When I click on an entry on the flexgrid, I want
the map to highlight the target.

End platform specific detail

So my question is, how are helper classes defined?

A colleague showed me some UML where the flexgrid, map and tree
classes were aggregates of a GUI class. Each of the aggregates has a
pointer to the GUI class which is stored when the class is
instantiated by the constructor.

If you use MFC why not do it the MFC way. It supports the document-view
model, and what you describe fits it IMHO. Your document can have all the
data, and you have 3 view to represent it, tree, map and grid. In that case
it's not important whether they all live undes a single frame with splitters
or some in distinct windows, or even if you have multiple of some views.
On any view you handle the user event -- like D&D. You know what is dropped
from the oledatasource, and figure out on what is it dropped. Then call the
document with the event. (all views have a direct link to the document).
The document rearranges the binary data, and sends update notification to
all views broadcasting what actually changed (calling
UpdateAllViews(pOriginatingView, longHint, pObjHint)).

There's a good tutorial on MFC and doc/view architecture in MSDN, look up
the SCRIBBLE sample, and follow the steps.

Another approach could be to use the frame as the dispatch center. As your
panes are child windows and all can post messages to GetParentFrame(). Like
initially registering themselves for some events, then post their events.
And the frame could then dispatch the messages to the interested parties.

Quote:
He explained that I would call a method in the GUI class from one of
the aggregates and the GUI method would route the messages to the
appropriate aggregates.

That also caould be done, then foregt the MFC and do everything by hand. I
currently see no benefit on working out another set of wheels.

Paul



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.