More newbie questions...

Göran Hultgren gohu at rocketmail.com
Sun Apr 9 18:39:08 UTC 2000


Hi Mark and others!

--- Mark <marquedej at onebox.com> 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?

Well, let me take a stab in clarifying this a bit.
Objects are... well, simply objects :-).
For example a car object represents one specific car let's say MY car - a Nissan SX200.

Your car is ANOTHER car object. An object typically (almost always) carry some sort of state. For
a car object this could perhaps be mileage, amount of gasoline in the tank, current
position/speed/direction and registration number. Note that all of these states typically are
different for your car compared to mine.

Ok, so what is this "class" thingy then? Well, a class is a description of a certain kind of
object. In most other OO languages like C++ and Java, a class is simply, as you said, a
"definition" of an object - a source code construct and not typically something that exists during
runtime.

BUT in Smalltalk classes are themselves ALSO objects. Two good analogies to classes "the Smalltalk
way" IMHO is too see them as factories or blueprints (something for concrete than the word
"definition") for making objects.

A factory/blueprint carry state that describes how to construct an object. So... to answer your
question about why they look so different - they ARE different. A car factory is an object quite
different from a car, right? A car factory typically carries state about how to construct a car
object. In Smalltalk this translates to what instance variables a car object should have and what
messages a car object should be able to handle. But we can add other state to the class if we want
to - perhaps we want our car factory to keep track of how many cars it creates using a counter.
Then we would typically add a so called "class instance variable" to the class.

It is not far fetched to imagine sending a message to a factory in order to create an object.
Since classes are objects you can "hold" them in variables and send them around as arguments in
messages etc. just like other objects.

I do not know if my little rambling made anything clearer. :-)

regards, Göran

=====
Göran Hultgren, goran.hultgren at bluefish.se
icq#:6136722, GSM: +46 709 472152, http://www.bluefish.se
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com





More information about the Squeak-dev mailing list