[DOCS] ProtoMorph (was: Thinking about redoing Morphic)
Hannes Hirzel
hannes.hirzel.squeaklist at bluewin.ch
Thu Feb 13 09:15:45 UTC 2003
Hi all
Todd Blanchard sent in a very nice tiny changeSet named
MinimalProtoMorph.1.cs.
It takes Alejandro F. Reimondos idea of cloning applied to just one
class - the class Morph
It includes the notion of adding methods as you go along
worked on by Andrew P. Black, Adam Spitz and Ned Konz in another thread
'adding methods to the debugger'
but in this case automatically by copying the missing methods from
another class.
I tried it out and it worked excellently well.
Below are some notes I did.
Hannes
------------------------------------------------------------------------
----
Concept
------------------------------------------------------------------------
----
The changeset only includes class ProtoMorph with 7 (seven) methods. The
most important one is
doesNotUnderstand: aMessage
Morph sourceCodeAt: (aMessage selector) ifAbsent: [ super
doesNotUnderstand: aMessage].
self cloneSelector: (aMessage selector).
^self perform: (aMessage selector) withArguments: (aMessage arguments).
It basically copies the methods not known to ProtoMorph from the Morph
class itself.
------------------------------------------------------------------------
----
Using ProtoMorph
------------------------------------------------------------------------
----
1)
Open a new MorphicProject
2)
File in MinimalProtoMorph.1.cs
3)
Open a Workspace
4)
Type
ProtoMorph new openInWorld
and evaluate it
5)
A debugger window pops up with an error message in method #wantsSteps
Comment out the code in #wantsSteps in ProtoMorph in a SystemBrowser
(important: not in the debugger that doesn't work in this case)
and add
^false
6)
Reevaluate
ProtoMorph new openInWorld
This time the process is completed and you get a new ProtoMorph at the
default position
(upper left corner) in the default color (blue)
(Actually you have two ProtoMorphs as you find out if you bring up the
halos by clicking the blue button and moving them.
7)
In the Workspace type
ProtoMorph methodDict size
and evaluate and print it
You get 172 methods (in Squeak 3.5a)
8)
This whole process makes understanding the
class Morph much more tackable.
Browse ProtoMorph in the SystemBrowers
It is an interesting experience
9)
Bring up the halos of a ProtoMorph again
and resize the ProtoMorph
Reevaluate
ProtoMorph methodDict size
And you get 186 methods
10)
Bring up the halos again and choose the
recolor handle
Reevaluate
ProtoMorph methodDict size
And you get 190 methods.
If you embed one ProtoMorph in another morph
the number of methods augments to 256.
And so one ...
------------------------------------------------------------------------
----
Conclusion
------------------------------------------------------------------------
----
I consider ProtoMorph to be a good learning and
documentation aid. It surely helps the refactoring process.
Many method categories of ProtoMorph
include only one or two methods. They often are actually the
"hooks" to entire subsystems.
This process elaborated a bit further may allow you to
come up with your own NewMorph hierarchy which includes
only the things you want.
More information about the Squeak-dev
mailing list
|