[Newbies] OrderedCollection if imageMorphs
bert at freudenbergs.de
Mon Nov 9 16:24:39 UTC 2009
On 09.11.2009, at 02:08, Christine Wolfe wrote:
> Oh wow! thanks - having the sample code will be a huge help. I'll
> give it a
> -----Original Message-----
> From: Randal L. Schwartz [mailto:merlyn at stonehenge.com]
> Sent: Sunday, November 08, 2009 8:03 PM
> To: Christine Wolfe
> Cc: beginners at lists.squeakfoundation.org
> Subject: Re: [Newbies] OrderedCollection if imageMorphs
>>>>>> "Christine" == Christine Wolfe <cwdw01 at earthlink.net> writes:
> Christine> Oh, I'm so so sorry - I thought it was OK to ask dumb
> Christine> the newbie forum (blush) I'll try to figure out how to
> make an
> Christine> instance variable an order collection.
> It's perfectly OK, and that's why you were corrected. :)
> Basically, you'll do the following:
> * add an instance variable: contents
> on your instance side, add:
> super initialize.
> contents := OrderedCollection new.
> then for each item of the collection protocol, delegate it, as in:
> add: anItem
> ^contents add: anItem.
> includes: anItem
> ^contents includes: anItem.
> ^contents size.
> and so on. If you get really tired of adding all of them,
> just add them as you need them (when the debugger tells you :).
Why would you want to add all these methods and your own class in the
first place? They are there already, perfectly usable.
> If you wanna get really tricky, you can add a #doesNotUnderstand:
> handler to
> perform the method on the contents variable, but that can mess up your
> debugging, so it's better if you don't.
Err, now that goes into the land of advanced applied magic. Please
ignore that last paragraph ;)
Christine, if you want an OrderedCollection of ImageMorphs (as you
wrote in the subject) then do just that. Create an OrderedCollection,
not a subclass of it. And add ImageMorphs, not subclasses of
ImageMorphs (unless they indeed do specific processing - but even then
I'd probably make only one ImageMorph subclass and customize that).
It is often unnecessary to create your own classes for everything. For
example, if the only difference of a regular ImageMorph and your own
Morph subclass is the image it shows, then do not create a subclass.
Just assign the right image. And maybe assign an event handler, no
need for subclassing there either.
OTOH, when I look at your high-level goal "I’m making a pinball
machine in which the little ball follows the order of execution of a
student entered flowchart" I don't really see the need for a
"SymbolArray" nor even "OrderedCollection of ImageMorphs". Maybe you
should design the UI first and then implement whatever is necessary to
make it work?
- Bert -
More information about the Beginners