Re: new Desktop::Editor
- From: thudson cygnus com
- To: Tom Tromey <tromey cygnus com>
- CC: Dave Camp <campd oit edu>, Martijn van Beers <martijn earthling net>, gnome-components-list gnome org
- Subject: Re: new Desktop::Editor
- Date: Wed, 22 Sep 1999 09:00:43 -0400
Tom Tromey wrote:
>
> I'm personally partial to a loose coupling, via an event system,
> instead of a tight coupling via callbacks. I'm curious to know if
> anybody has reasons (other than feelings) to choose one over the
> other. Reasons based on actual experience, for instance.
>
I agree. I meant callbacks as only a generic term. I really like
the methods used in libSigC++. I'm not experienced enough w/
CORBA/Orbit to see how to implement something similar.
My only experience is w/ a system implemented in C++ that borrowed
heavily from patterns used in Java, implementing Listener interfaces
for each event you wish to receive. The downsides other than tight
coupling is; increased compilation times due to changes in the
base interface header, duplication of a lot of boilerplate type
code, and additional hoops you have to go through to provide
thread safety.
We eventually modified the system to be a hybrid of callbacks and
events to handle this last issue. Instead of the class being listened
to calling the listener methods directly, it queued an event in the
main thread to notify itself to call the listener methods. Fairly
ugly.
class Generator: public EventHandler
{
// called to generate an event
void NotifyListeners
{
Event* e = new Event;
// post event to main thread
App->postEvent(this,e);
}
// called in main thread
void HandleEvent(Event* e)
{
for (/* each listener */)
listener->CallbackMethod(e)
}
};
Thomas
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]