[squeak-dev] Use of #asMorph

Igor Stasenko siguctua at gmail.com
Sun Mar 14 00:34:43 UTC 2010


Hello, lists

i'd like to ask an intricate question.

Suppose that your morph acts as a container, which needs to hold an
items, retrieved from a model object.
A model's elements could be any object, and may choose to represent
them in a way they like it.
So, for instance, if we taking a list, the list elements is
represented by a morphs not simple strings.

Now, a question:
is it fine to use #asMorph as a message to 'convert' a model's item to
a morph, which then can be used to reflect given item in list?

I.e. something like:
model itemsDo: [:item |
   self addMorph: item asMorph ]

In this way, a list is built from morphs, and each list item choosing
by itself, what morph should be used to represent itself in a list.
But by saying A, we usually need to say B: an object could choose
different representation depending on container's properties:

model itemsDo: [:item |
   self addMorph: (item asMorphIn: self) ]

So, for example, a compiled method, could choose to represent itself
in a list as a simple string with own selector,
while in text editor it could choose to display own source code.

What you would do in such case?


-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list