newbie question: poolDictionaries

Ned Konz ned at bike-nomad.com
Fri Mar 7 20:36:44 UTC 2003


On Friday 07 March 2003 11:52 am, Stephane Rollandin wrote:
> Two questions, actually
>
>
> 1) in the following definition:
>
> Object subclass: #SomeSubclass
> 	instanceVariableNames: ''
> 	classVariableNames: 'A B'
> 	poolDictionaries: ''
> 	category: 'Some-Category'
>
> what are poolDictionaries ?

poolDictionaries are sort of like containers of class variables, but 
are visible to more than one class hierarchy. So you can share (say) 
constants between two or more otherwise unrelated classes. You can 
see this in Text and StrikeFont. What's interesting (other than 
visibility) is that any key (symbol) in a pool dictionary can be used 
directly in your code.

i.e. TextConstants has a key #Ctrlz so I can use Ctrlz in any method 
in any class that has TextConstants as a pool dictionary, and I'll 
get its value from the pool dictionary.

Actually, class variables are also held in a dictionary like this, but 
aren't shared. (i.e. to get to a class variable A from an instance 
method you could go:

A

or

self class classPool at: #A

This isn't normally all that interesting, except when you're 
inspecting an object and want to look at its class variable.

> 2) if I subclass SomeSubclass like this:
>
> SomeSubclass subclass: #SomeSubSubclass
> 	instanceVariableNames: ''
> 	classVariableNames: ''
> 	poolDictionaries: ''
> 	category: 'Some-Category'
>
>
> it appears that the class variables A and B are shared by both
> classes. Is it possible to have some kind of a class variable that
> can store different values along the inheritance chain ? (e.g. A is
> 5 in SomeSubclass and A is 'hello' in SomeSubSubclass)
>
> if not, how do you get this behaviour ?

This is known as a "class instance variable". Since classes are 
themselves are objects, they can have instance variables of their own 
(in addition to specifying the names of the instance variables for 
their instances). You get to this by selecting the "class" button in 
the browser when viewing a class definition.

You'll see:

SomeSubclass class
	instanceVariableNames: 'a'

Note that these names, being names of instance variables, are not 
generally capitalized.

You can see this used (for instance) in Player.

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE



More information about the Squeak-dev mailing list