Setting up a dependency mechanism in Squeak

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting up a dependency mechanism in Squeak

David Finlayson-4
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?

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.

Thanks for any advise.

David
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a dependency mechanism in Squeak

Rob Rothwell
If I understand you right, you could use Announcements...your "dependent object" registers for Announcements it is interested in, and takes action when something is announced.

You can see the following for a web type of example, and I could probably get you started with a simple example as well:

http://onsmalltalk.com/programming/smalltalk/maintaining-loose-coupling-in-seaside-components/

Rob


On Fri, May 23, 2008 at 5:44 PM, David Finlayson <[hidden email]> 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?

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.

Thanks for any advise.

David
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a dependency mechanism in Squeak

David T. Lewis
In reply to this post by David Finlayson-4
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

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a dependency mechanism in Squeak

David Finlayson-4
That is refreshing news. Lewis's book is pretty good, glad it still
applies. He described things well.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners