[squeak-dev] Progress bar design pattern

Yoshiki Ohshima yoshiki at vpri.org
Thu Mar 31 22:06:55 UTC 2011


At Thu, 31 Mar 2011 18:53:29 -0300,
Martin Dias wrote:
> 
> What you sent makes me think...
> 
> I am not convinced of this other solution, but with announcements could be:
> 
> algorithm
> self doA.
> self announce: (WorkAnnoucement finished: #doA).
> self doB.
> self announce: (WorkAnnoucement finished: #doB).
> self doC.
> self announce: (WorkAnnoucement finished: #doC).
> 
> and the specific observer subscribed to this algorithm knows what percentage corresponds to each selector. And you could
> easily plug an observer that logs to Transcript.

  Well, say self has an inst var called progress, which may be nil or
something that understands #value:.

algorithm
	self doA.
	progress ifNotNil: [progress value: #doA].
	self doB.
	progress ifNotNil: [progress value: #doB].
	self doC.
	progress ifNotNil: [progress value: #doC].

All you have to do is to assign a block that looks like:

  [:v | Transcript print: v; cr].

to progress to get Transcript.  Or, you can assign the bar block from
displayProgress: and get UI update.  Or, the block can have some
#announce: if you want to get multiple parties to get notified.

  #value: is generic.  A block understands it but also you can just
create a class with #value: and let it do anything you want.  Again,
if the original goal it to "decouple" the algorithm from progress
notification, complicating the entire thing with announcement is
backward.

-- Yoshiki



More information about the Squeak-dev mailing list