Re: software design question
"Jorge Godoy" <godoy@ieee.org > wrote in message
news:l69kf1-9e8.ln1@winterm ute.g2ctech...[color=blue]
> On Sunday 08 February 2004 01:24 John Roth wrote in
> <102bb30d5422pd 4@news.supernew s.com>:
>[color=green]
> > I suspect you've got the callback logic backwards. The basic
> > layering pattern is "call down, notify up," and it's the upper
> > layer's responsibility to request the notification.
> >
> > To explicate: the GUI module calls the domain
> > module for service. It also calls the domain module
> > to register callbacks, passing the function that it
> > want's called.
> >
> > When the domain layer has something it wants to
> > tell the GUI layer, it simply runs a (possibly empty)
> > list of callback functions.[/color]
>
> Can you exemplify it?
>
> I'm very interested on such approach and I'm going to read a little
> more about it, but examples in Python would help a lot.[/color]
A simple notify class:
---------------------------------------------
class Notify(object):
def __init__(self):
self.listenerLi st = []
def sendMessage(sel f, event):
for callback in self.listenerLi st:
callback(event)
return
def addListener(sel f, callback):
self.listenerLi st.append(callb ack)
def removeListener( self, callback):
self.listenerLi st.remove(callb ack)
---------------------------------------------
Here's a place where I instantiate it:
--------------------------------------------------------------
class ALocation(objec t):
def __init__(self):
self._latitude = LatitudeContain er()
self._longitude = LongitudeContai ner()
self._placeName = StringContainer ()
self._titleNoti fier = A4Base.Notify.N otify()
self._latitude. addListener(sel f._titleUpdated )
self._longitude .addListener(se lf._titleUpdate d)
---------------------------------------------------------------
and the routine that uses this notifier:
--------------------------------------------------------
def _titleUpdated(s elf, event):
self._titleNoti fier.sendMessag e(event)
--------------------------------------------------------
LatitudeContain er and LongitudeContai ner both derive
from BaseContainer (through StringContainer , but that
doesn't add anything to this example):
-------------------------------------------------------
class BaseContainer(o bject):
def __init__(self):
self._notifier = A4Base.Notify.N otify()
def addListener(sel f, callback):
return self._notifier. addListener(cal lback)
def removeListener( self, callback):
return self._notifier. removeCallback( callback)
def _sendMessage(se lf, message):
return self._notifier. sendMessage(mes sage)
---------------------------------------------------------
here's the routine in LatitudeContain er that fires
off the notification:
------------------------------------------------------
def _setStringValue (self, value):
self.parseLat(v alue)
if self._stringVal ue != value:
self._stringVal ue = value
self._sendMessa ge(value)
-------------------------------------------------------
HTH
John Roth
[color=blue]
>
>
> TIA,
> --
> Godoy. <godoy@ieee.org >[/color]
"Jorge Godoy" <godoy@ieee.org > wrote in message
news:l69kf1-9e8.ln1@winterm ute.g2ctech...[color=blue]
> On Sunday 08 February 2004 01:24 John Roth wrote in
> <102bb30d5422pd 4@news.supernew s.com>:
>[color=green]
> > I suspect you've got the callback logic backwards. The basic
> > layering pattern is "call down, notify up," and it's the upper
> > layer's responsibility to request the notification.
> >
> > To explicate: the GUI module calls the domain
> > module for service. It also calls the domain module
> > to register callbacks, passing the function that it
> > want's called.
> >
> > When the domain layer has something it wants to
> > tell the GUI layer, it simply runs a (possibly empty)
> > list of callback functions.[/color]
>
> Can you exemplify it?
>
> I'm very interested on such approach and I'm going to read a little
> more about it, but examples in Python would help a lot.[/color]
A simple notify class:
---------------------------------------------
class Notify(object):
def __init__(self):
self.listenerLi st = []
def sendMessage(sel f, event):
for callback in self.listenerLi st:
callback(event)
return
def addListener(sel f, callback):
self.listenerLi st.append(callb ack)
def removeListener( self, callback):
self.listenerLi st.remove(callb ack)
---------------------------------------------
Here's a place where I instantiate it:
--------------------------------------------------------------
class ALocation(objec t):
def __init__(self):
self._latitude = LatitudeContain er()
self._longitude = LongitudeContai ner()
self._placeName = StringContainer ()
self._titleNoti fier = A4Base.Notify.N otify()
self._latitude. addListener(sel f._titleUpdated )
self._longitude .addListener(se lf._titleUpdate d)
---------------------------------------------------------------
and the routine that uses this notifier:
--------------------------------------------------------
def _titleUpdated(s elf, event):
self._titleNoti fier.sendMessag e(event)
--------------------------------------------------------
LatitudeContain er and LongitudeContai ner both derive
from BaseContainer (through StringContainer , but that
doesn't add anything to this example):
-------------------------------------------------------
class BaseContainer(o bject):
def __init__(self):
self._notifier = A4Base.Notify.N otify()
def addListener(sel f, callback):
return self._notifier. addListener(cal lback)
def removeListener( self, callback):
return self._notifier. removeCallback( callback)
def _sendMessage(se lf, message):
return self._notifier. sendMessage(mes sage)
---------------------------------------------------------
here's the routine in LatitudeContain er that fires
off the notification:
------------------------------------------------------
def _setStringValue (self, value):
self.parseLat(v alue)
if self._stringVal ue != value:
self._stringVal ue = value
self._sendMessa ge(value)
-------------------------------------------------------
HTH
John Roth
[color=blue]
>
>
> TIA,
> --
> Godoy. <godoy@ieee.org >[/color]
Comment