[Newbies] System Browser: instance vs. class

lanas lanas at securenet.net
Mon Feb 1 00:22:52 UTC 2010

Le Dimanche, 31 Janvier 2010 15:13:50 -0800,
merlyn at stonehenge.com (Randal L. Schwartz) a écrit :

> A class is always a singleton.  There is only one class named Car
> in the system.  However, there can be many car instances, usually
> created by sending "new" to "Car".
> In the Car class, you'd hold information collectively about all cars,
> such as the default specifications or number of cars produced.
> In each car instance, you'd hold information about a specific car,
> like its color or owner.

Thanks for pointing that out.  In the book's example though, the
variable is declared as instance variable.  To go along with class
variables holding information for all instances, it should instead
be declared as class variable isn't it ? (Although it does work like

Object subclass: #CarAssembler
  instanceVariableNames: 'factory'
  classVariableNames: ''

CarAssembler class>>using: aCarFactory
  ^self new factory: aCarFactory

That is, if one thinks that a single car factory should be shared
amongst all instances of CarAssembler.  I think not and I would make it
local to each object instance.


More information about the Beginners mailing list