[Prev][Next][Index][Thread]
Re: help with DUIM application
On Wed, 14 Jun 2000 09:45:01 -0400 (EDT), johncwhi@my-deja.com wrote:
> Now how this fits into the suggestions given already... Is the
> call-in-frame method the equivalent of the Notify() method? I'll have
> to think about that some more.
Loosely coupling the components like this is orthogonal to the issue of
combining the threading. It might be done as follows:
8<----------------------------------------------------------------------
begin
let frame = make(<my-frame>);
add!(*hooks*, method (data) call-in-frame(frame, update-my-frame, data) end);
make(<thread>, function: start-data-capture);
start-frame(frame); // NB uses up main thread
end;
define constant *hooks* = make(<stretchy-vector>);
define method start-data-capture ()
while (#t)
let data = blocking-read-for-device-data();
do(method (hook) hook(data) end, *hooks*);
end;
end method;
define method update-my-frame (frame :: <my-frame>, data)
// insert display changing code here
// (gets run on frame thread)
end method;
8<----------------------------------------------------------------------
Now anyone can add themselves to hooks to get told about new data.
The 'Pattern' literation generally assumes message-passing OO-style. Hence they
are forced to think in terms of protocols (eg Notify), which aren't necessary
in Dylan although you could define them if you wanted to:
8<----------------------------------------------------------------------
begin
let frame = make(<my-frame>);
add!(*observers*, frame);
make(<thread>, function: start-data-capture);
start-frame(frame); // NB uses up main thread
end;
define constant *observers* = make(<stretchy-vector>);
define method start-data-capture ()
while (#t)
let data = blocking-read-for-device-data();
do(method (observer) notify(observer, data) end, *observers*);
end;
end method;
define method notify (frame :: <my-frame>, data)
method (data) call-in-frame(frame, update-my-frame, data) end);
end method;
define method update-my-frame (frame :: <my-frame>, data)
// insert display changing code here
// (gets run on frame thread)
end method;
8<----------------------------------------------------------------------
__Jason
_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp
References: