[Newbies] Creating a Class>>newX method directly from a pre-existing instance X

Erich Groat erichgroat at gmail.com
Sat Jun 9 21:04:50 UTC 2012


Hi all,

I was wondering if there are any built-in facilities for taking a
particular instance a class *X*, call it *anX,* and creating from it a
class method that returns an identical instance of *anX* for future use.

For example, say I'm futzing around in a workspace with an instance of a
class called *InteractiveWindowShape*, tweaking things so that I have a
nice window with all the colors and proportions and buttons I want, perhaps
using Morphs to create the thing dynamically (so it's some kind of Morph
object). In the course of this I get an instance of *
anInteractiveWindowShape* that I am satisfied with, all the instance
variables set just right. Let's call this object* | idealShape |*. It's
just sitting there, rather vulnerably, in a workspace, the result of my
using various screen tools over the last half hour. Now, I don't just want
to *save* this object: I want to be able to create an identical one
whenever I like. So what I want is a Class method, *InteractiveWindowShapes
class>>**newIdealShape,* that creates an instance exactly like *idealShape.*

Is there a message I can send *to this instance* *idealShape* that would
return a block of code that would act as a class method, which I could then
call *newIdealShape*, and which would return an identical instance?

I suspect such a general method might not exist, due to the potential
hazards surrounding the deep copy problem; I also suspect I may not be
imagining the best sort of solution to my problem. Is there a strategy for
this?

Thanks all!

Erich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20120609/c85cd2db/attachment.htm


More information about the Beginners mailing list