[Newbies] Setting up a dependency mechanism in Squeak

David T. Lewis lewis at mail.msen.com
Sat May 24 00:08:22 UTC 2008


On Fri, May 23, 2008 at 02:44:04PM -0700, David Finlayson wrote:
> In the Art and Science of Smalltalk by Simon Lewis, there is a lengthy
> discussion of Smalltalk's dependency mechanism (yourObject
> addDependent: myObject; myObject changed, etc.) . A few of the
> examples of Morphic (Squeak by Example, Squeak: Object Oriented Design
> with Multimedia Applications) show examples sending the "changed"
> message which I assume triggers a dependency update the same as or
> similar to the dependency mechanism described by Lewis. But the
> examples are too trivial to see this through completely. Is this still
> the way to set up a many-to-one dependency relationship between
> objects in Squeak?

Yes, this is still the right way to do it. There are other mechanisms
available, but in most cases the original is still the best.

> My program is pretty simple: I am creating a navigation display for a
> boat. The boat's position and other interesting variables are
> transmitted to the program via UDP packets over the network and these
> are visualized in the user-interface by a set of widgets (which the
> pilot can pick from and move around). I plan on having a master object
> that contains the latest information from the various UDP packets and
> I want the widgets to depend on the master, so that when (for example)
> the position of the boat is updated, the little widget representing
> the boat moves appropriately. All of this is obviously do-able (and
> not too different than Etoys), but I'm still learning how to set it up
> in Squeak.

You are doing exactly the right thing. Your master object can notify
its dependents with "self changed: #position", and the dependents can
implement the #update: method. When they see the #position change, they
ask the master object for the current position and update their display
accordingly.

In MVC terminology, your master object is acting as the model, and
the widget that displays its position is a view on your model. The
dependency mechanism ties them together, and allows you to have one
or more "views" of the position of the boat.

Dave



More information about the Beginners mailing list