Class vs. Instance (was: Re: More newbie questions...)

Mark marquedej at onebox.com
Sun Apr 9 01:44:04 UTC 2000


So, if I wanted to sub-class a class, would I put my code in the "Instance"
area or in the "Class" area?

Oh ... wait ... do you mean that anything I put in the "Class" area will
be available as "static" objects and anything I put in the "Instance"
area needs to be created with "new"?

Specifically, I'm playing in the Morphic world. I wanted to create a
button to launch Scamper. Why? I don't know; just to do it! <grin>

I did get one working. I called it "WebButton" and placed it under "BasicButton"
which means it ended up in the "Morphic-Scripting" category, for some
reason. (huh?! <grin>)

In it, I added "handlesMouseUp: evt" and "mouseUp: evt". "handlesMouseUp"
simply returned true and "mouseUp" executed "Scamper new openAsMorph".

This seems to work. However, I don't think my code should be placed in
the "Morphic-Scripting" category.

Also, the button doesn't behave as I'd expect. If I click on the button,
it doesn't change visibly and if I move the mouse off the button before
I release the mouse button, it still executes the "mouseUp" event as
if I had remained inside the button.

(More clues for the clueless, please!)

	-- Mark

--------------------------------------------------
marquedej at onebox.com - email
(760) 708-6400 x1067 - voicemail/fax



---- John Clonts <jclonts at mastnet.net> wrote:
> Mark wrote:
> > 
> > Aha! I found it. <grin>
> > 
> > Ok. Remembering my C++, an "instance" is an actual instatiation of
> a
> > class (or object) and the "class" is simply the definition.
> > 
> > Do these terms still apply? And, if so, why do the instances look
> so
> > different from the classes?
> > 
> > (Btw, thanks for the prompt responses and for putting up with these
> questions!)
> > 
> >         -- Mark
> > 
> 
> Pretty much they still apply, just more so!
> 
> The class is the factory of instances, the difference is that in
> Smalltalk the class is an object too.
> 
> Others have been more explanatory, but I will add this example:
> 
> class FillInTheBlank
> {
>   public:
>     static void * request(){ ... }
> };
> 
> main()
> {
>    // smalltalk: ans1 := FillInTheBlank request.
>    void * ans1;
>    ans1 = FillInTheBlank::request();
> 
>    // smalltalk:   
>    //    fib := FillInTheBlank new. ans2 := fib request. "wrong"
>    FillInTheBlank fib;
>    ans2 = fib.request();
> }
> 
> Like c++ static methods ("member functions"), smalltalk class-side
> methods require no specific instance of the class to operate on (ans1
> above).  Unlike c++, class-side methods are *not* invoked on onjects
> (ans2 above does not work for smalltalk).
> 
> Cheers,
> John
> 
> 

__________________________________________________
FREE voicemail, email, and fax...all in one place.
Sign Up Now! http://www.onebox.com





More information about the Squeak-dev mailing list