472,374 Members | 1,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

OO design and communication between classes

I have a class FrameListener, that contains a method which loops
continually, if this method returns false then the application exits.
I have a class KeyListener, that gets input from the user.

Both these classes are 3rd party and beyond my control. I can however derive
from these as long as the base functionality is intact. I did indeed derive
from these and make my own custom functionality on top.

My question is how can I design things so that the KeyListener can let the
FrameListener know when a user hits escape so that the FrameListener can
exit the application?

I am not sure whether to

(A) make a class derived from both FrameListener and KeyListener holding
some bool like m_continue_loopig

(B) keep them seperate as suggested by the 3rd party and make some
event/event handler design (C++ doesn't directly support this as far as I
know)

(C) have FrameListener contain KeyListener (i guess KeyListener would have
to take a FrameListener reference in its constructor)

(D) ...any suggestions?

I am sure this kind of communication between objects is common. What kind of
things should I ask myself and what designs should I consider?

Thanks.
Christopher
Jul 23 '05 #1
1 2179
On 2005-05-30, Christopher <an**@nospam.net> wrote:
(A) make a class derived from both FrameListener and KeyListener holding
some bool like m_continue_loopig
Very messy -- arguably an abuse of inheritance.
(B) keep them seperate as suggested by the 3rd party and make some
event/event handler design (C++ doesn't directly support this as far as I
know)
This is the most scalable option. When/if you have more objects that need
to talk to each other, the other solutions will start to get unwieldy. Given
what you've said about your third party toolkit, doesn't it have any support
for event handling ?
(C) have FrameListener contain KeyListener (i guess KeyListener would have
to take a FrameListener reference in its constructor)


This would work but wouldn't generalise very well. What happens when you have
more objects that need to talk to each other ? Any synchronisation code
that you need to make sure that two things don't write to an address at the
same time, and/or one thing isn't reading while another is writing, would
need to be duplicated whereas if you had some sort of general event model,
you could conveniently encapsulate this in a class.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Uwe Mayer | last post by:
Hi, I have the following inter-class relationships: __main__: (in file LMCMain.py) imports module FileIO defines class LMCMain instanciats main = LMCMain(...) FileIO.py:
2
by: | last post by:
I have this class ------------- class Component { /*class*/ Data *d; /*class*/ Draw *a; }; ------------- from "Component" derive classes like "TextBox", "Button", "Label", "ComboBox" etc from...
0
by: RM | last post by:
We have several hundred classes that essentially implement a variety of features in our system. Communication between classes is via message passing. Each class acts like a process, getting a time...
2
by: Leonardo D'Ippolito | last post by:
Hi! I have two .NET win apps that need to communicate on a TCP/IP network. 'App A' must ask 'app B' if it's allowed to do some task, and 'app B' must authorize or prohibit it. How can I do...
21
by: dast | last post by:
Hi, I'm having trouble letting my background thread tell my main thread what to do. I'm trying to tell my main thread to open a form, but when my background thread ends, the form that I...
12
Banfa
by: Banfa | last post by:
I was mildly concerned when I saw else where on the forum on of our experts express the opinion that software design saw not required and their prefered design method of development was to just start...
19
by: adriancico | last post by:
Hi I am working on a python app, an outliner(a window with a TreeCtrl on the left to select a document, and a RichTextBox at the right to edit the current doc). I am familiarized with OOP...
0
by: WebCM | last post by:
I hope you can spend some time and help me to select proper application design and programming issues. :) I'm making new version of CMS. I've been mostly theorizing about it for a recent months. ...
8
by: =?Utf-8?B?QmVu?= | last post by:
Hi, I have a couple of questions about the proper design of classes. I'll use a simple Customer class for my question. 1) Lets say that I have this Customer class like I said, and I want to...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.