[NEWBIE] Question on dependencies in Squeak

Bob Arning arning at charm.net
Sat Oct 9 20:46:49 UTC 1999


On Sat, 9 Oct 1999 10:43:07 -0400 (EDT) swan <swan at hayman.cs.umass.edu> wrote:
>So, how do I do dependencies in a Morphic framework? I've heard that
>Morphic can be viewed as a combination View/Controller. How do I set it up
>that my UI elements don't know about each other, and know very little
>about the model (access methods only), and the model can tell morphics to
>update but doesn't know anything about how many there are, how they work,
>and what they are like?
>
>Any pointers or references would be greatly appreciated.

Hi Russell,

The beginning of your message indicates that you have seen the answer, but perhaps you were looking for something more complicated. In a nutshell, here's how it goes:

1. Some uiThing is created to provide a view on a modelThing. This uiThing says 

	modelThing addDependent: self

 so that the uiThing will be notified when the modelThing changes.

2. At some point, the modelThing does change and it says

	self changed: #someAspectOfModelThing

3. Since the uiThing was registered as a dependent of the modelThing, this leads to something like 

	uiThing update: #someAspectOfModelThing

being sent by the dependency mechanism (put a halt before step 2 and follow it through to see just how this happens).

4. The uiThing has a method that looks like:

update: aSymbol

	aSymbol == #someAspectOfModelThing ifTrue: [
		self updateThePartsOfMeDependentOnSomeAspectOfModelThing
	].
	aSymbol == #anotherAspectOfModelThing ifTrue: [
		self updateThePartsOfMeDependentOnAnotherAspectOfModelThing
	].
	"...etc.."

This meets the criteria of your question:
a. The modelThing does not directly know what uiThings are dependent on it (it *could* find out by examining whatever structures the dependency mechanism uses to remember the linkages, but this is a rare occurrence).
b. The uiThing knows nothing about other uiThings that may be interested in the modelThing.
c. The uiThing knows very little about the modelThing other than

"When I see #someAspectOfModelThing in my update method, I had better ask the model for #someAccessibleAttribute and display the result appropriately."

 Very often these two symbols are the same so that the modelThing says:

	self changed: #birthDay

and a uiThing that was displaying the birthday would say (effectively)
	
	someDisplayWidget contents: modelThing birthday nicelyFormatted

As to some of the variants of #changed: and #update: you mention, these are interesting to simulate. There is no requirement that the arguments to these two methods actually be Symbols - they could be anything.

The modelThing could say

birthday: aDate

	birthday _ aDate.
	self changed: {#birthday. birthday}.

In which case the uiThing could look like:

update: arguments

	arguments first == #birthday ifTrue: [birthdayWidget contents: arguments second].

The possibilities are unlimited.

Cheers,
Bob





More information about the Squeak-dev mailing list