lanas | 1 Feb 2010 01:22

Re: System Browser: instance vs. class

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
this).

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.

(Continue reading)

lanas | 1 Feb 2010 01:39

Using same class names

Hello all,

 Is there a way to have several classes with the same names and having
their scope limited to the current selected category ?  Eg.  I'd like to
experiment with the Abstract factory pattern and thus I would like to
make several tests, each in a category, like:

AL-AbstractFactory-1
AL-AbstractFactory-2

... and so on.  Each one is a variation and experiment. So I'd like to
keep the same class names but Squeak warns me that the CarPartFactory
I'm trying to create in AL-AbstractFactory-2 already exists in
AL-AbstractFactory-1.  Do I have to file the category out, remove it,
create a new test, file out that second test, remove it, then file in
the first test and such ?  

In other words, is there a way to quickly switch from one experiment
to the other when each of these experiments would use the same class
names and probably many of the same method names ?

By the way, in the System Browser, the row of buttons labeled browse,
senders, implementors, version, inheritance and such has
somehow disappeared.  Any new System Browser does not have that row of
buttons anymore.  Is there a way to bring them back short of reverting
to the original image.  This is Squeak 3.10.2.

Thanks for any suggestions,

Al
(Continue reading)

Randal L. Schwartz | 1 Feb 2010 02:00
Favicon
Gravatar

Re: Using same class names

>>>>> "lanas" == lanas  <lanas <at> securenet.net> writes:

lanas> In other words, is there a way to quickly switch from one experiment
lanas> to the other when each of these experiments would use the same class
lanas> names and probably many of the same method names ?

I think you'd need to use subclasses, and therefore your tests should
use parameterized class names.

--

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn <at> stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
lanas | 1 Feb 2010 02:15

Re: Using same class names

Le Dimanche, 31 Janvier 2010 17:00:25 -0800,
merlyn <at> stonehenge.com (Randal L. Schwartz) a écrit :

> I think you'd need to use subclasses, and therefore your tests should
> use parameterized class names.

Would you care to give an example ? - Thanks.

Al
K. K. Subramaniam | 1 Feb 2010 04:55
Picon

Re: Using same class names

On Monday 01 February 2010 06:09:35 am lanas wrote:
> Hello all,
> 
>  Is there a way to have several classes with the same names and having
> their scope limited to the current selected category ?  Eg.  I'd like to
> experiment with the Abstract factory pattern and thus I would like to
> make several tests, each in a category, like:
AFAIK, classes are variables in global scope in Squeak. Try inspecting:
   #Integer
and
   Smalltalk at: #Integer

> In other words, is there a way to quickly switch from one experiment
> to the other when each of these experiments would use the same class
> names and probably many of the same method names ?
You may want to use facade class and subclass your variant classes from it. 
E.g if you have classes Factory1, Factory2 etc. with the same methods, create 
a facade superclass and invoke methods using current method. e.g.

  Factory current myownmethod

See senders and implementors of "current" method for examples.

> By the way, in the System Browser, the row of buttons labeled browse,
> senders, implementors, version, inheritance and such has
> somehow disappeared.  Any new System Browser does not have that row of
> buttons anymore.  Is there a way to bring them back short of reverting
> to the original image.  This is Squeak 3.10.2.
See optionalButtons in Preferences.

(Continue reading)

Alex Schenkman | 1 Feb 2010 07:30

Re: System Browser: instance vs. class



On Mon, Feb 1, 2010 at 01:22, lanas <lanas <at> securenet.net> wrote:

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

I think this a pattern for instance creation.
The point is that you can clearly see what it takes to create a instance of CarAssembler, namely, a CarFactory.

Notice that:
self new               "will create the instance"
factory: a CarFactory  "is storing aCarFactory in the instance, not the class"




_______________________________________________
Beginners mailing list
Beginners <at> lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Jerome Peace | 1 Feb 2010 07:34
Picon
Favicon

Re: System Browser: instance vs. class

Hi lanas

Your instincts are correct.

The 'factory' variable should belong to the instance.

The important thing about messages is trying to keep strait who they are going to.

In this case the #factory message is sent to an instance of CarAssembler.
The message new is sent to the class usually denoted as CarAssembler class.
The message #new makes an instance which the message #factory then supplys with a value.

The class is there to manufacture assemblers and to keep track of the methods they know (e.g. #factory:).
The factory ivar is there to keep track of a second object which in your example was an instance of a class
that assembles a particular type of car.

The message #using: is a convenience. It is sent fo CarAssembler class inorder to create an instance of a
CarAssembler that will assemble a particular type of car according to its argument.

To touch on the question you asked, which was both methods work so which one is preferred. The answer is it's
designer choice. In the context of an application that made only a few different instances of car
assembler it might be simpler to get along with out the convenience method. If you are turning out car
assemblers by the dozens then the #using: method would keep your code shorter and clearer. 

Often times the answer to questions like your are "It depends." 

hth,

Yours in friendship and service, --Jerome Peace

--- On Sun, 1/31/10, lanas <lanas <at> securenet.net> wrote:

> From: lanas <lanas <at> securenet.net>
> Subject: Re: [Newbies] System Browser: instance vs. class
> To: beginners <at> lists.squeakfoundation.org
> Date: Sunday, January 31, 2010, 7:22 PM
> 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
> this).
> 
> 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.
> 
> Al
> _______________________________________________
> Beginners mailing list
> Beginners <at> lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
> 

      
Jerome Peace | 1 Feb 2010 07:52
Picon
Favicon

Re: Using same class names

Hi lanas,

Hmmm. Hyphens wont work they will be interpreted as subtraction messages.
Underscores won't work in squeak either. They have historically been used as assignment characters. (Old
story. In an ancient characterset they rendered as back arrows. Some oldtimes loved that and no ones
gotten them to update. Pharo has made a point to ween themselves but not yet squeak.)

So ALAbstractFactoryA and ALAbstractFactoryB would be good names for experimental classes. Then copy
the winning experiment to your main class name. 

Do you mean for these abstract classes to have subclasses? That could have difficulties.

Yours in service and curiosity, --Jerome Peace

--- On Sun, 1/31/10, lanas <lanas <at> securenet.net> wrote:

> From: lanas <lanas <at> securenet.net>
> Subject: [Newbies] Using same class names
> To: beginners <at> lists.squeakfoundation.org
> Date: Sunday, January 31, 2010, 7:39 PM
> Hello all,
> 
>  Is there a way to have several classes with the same names
> and having
> their scope limited to the current selected category
> ?  Eg.  I'd like to
> experiment with the Abstract factory pattern and thus I
> would like to
> make several tests, each in a category, like:
> 
> AL-AbstractFactory-1
> AL-AbstractFactory-2
> 
> ... and so on.  Each one is a variation and
> experiment. So I'd like to
> keep the same class names but Squeak warns me that the
> CarPartFactory
> I'm trying to create in AL-AbstractFactory-2 already exists
> in
> AL-AbstractFactory-1.  Do I have to file the category
> out, remove it,
> create a new test, file out that second test, remove it,
> then file in
> the first test and such ?  
> 
> In other words, is there a way to quickly switch from one
> experiment
> to the other when each of these experiments would use the
> same class
> names and probably many of the same method names ?
> 
> By the way, in the System Browser, the row of buttons
> labeled browse,
> senders, implementors, version, inheritance and such has
> somehow disappeared.  Any new System Browser does not
> have that row of
> buttons anymore.  Is there a way to bring them back
> short of reverting
> to the original image.  This is Squeak 3.10.2.
> 
> Thanks for any suggestions,
> 
> Al
> _______________________________________________
> Beginners mailing list
> Beginners <at> lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
> 

      
lanas | 2 Feb 2010 01:39

Get rid of an object

Hello all,

  Thanks for the comments, they're helpful.

  When creating and testing objects in the Workspace, what is the
procedure for getting rid of any ?  Is there a need to do so ?  Can
objects lay there around without ever being destroyed, their creation
(eg. the text that created them) erased from the Workspace.  Can
created objects linger in the image endlessly ?  I presume that while
they are still holding data they won't be grabage-collected isn't it ?

Al
lanas | 2 Feb 2010 01:45

Re: Get rid of an object

Le Lundi, 1 Février 2010 19:39:06 -0500,
lanas <lanas <at> securenet.net> a écrit :

>   When creating and testing objects in the Workspace, what is the
> procedure for getting rid of any ?  

I noticed that if I create the following and inspect it:

myCar := Car new.
myCar setCompany: 'Renault'.
myCar addEngine: 'Renault V4'.
myCar addDriveTrain: 'Renault DriveTrain'.

myCar will have these variables set.

Now, if I 'do it' once more on the first line the inspect window will
still show the same variables being set.  If I open another inspect
window on myCar I get the new object, without any variables yet set.

So it looks like objects of the same name are considered separate
entities.  I'd have thought that perhaps doing a 'do it' on myCar a
second time would have re-initialized the first existing object.

If I create 25 myCar for various tests, then there'll be 25 myCar
objects laying around in the image ?  How to get rid of them ?

Al

Gmane