newbie question: poolDictionaries

Norton, Chris chrisn at Kronos.com
Fri Mar 7 21:02:42 UTC 2003


On Friday 07 March 2003 11:52 am, Stephane Rollandin asked: "What are pool
dictionaries?"

Hi Stephane.

To elaborate on what Ned Konz wrote, I'd like to say that Pool dictionaries
are typically used to share useful state (often this means sharing
constants) between several classes.  And, as Ned pointed out, pool
dictionary elements (the dictionary values) can be directly referenced in
the class methods (on both the class and instance side) by simply
referencing their keys.

Pool dictionaries are often used to define and group together various system
resources.  These resources, like operating system constants, only need to
be defined in a single pool.  All classes who reference that pool have
access to the constants.  Pools are a kind of global state that is
constrained in scope to be referencable from specific, user-specified,
classes.

In other Smalltalks that are more tightly integrated with host operating
systems, pool dictionaries are sometimes used to hold onto key system
resources that may in fact reside outside of Smalltalk's memory.  In cases
where large bitmap files are needed, for example, it makes sense to share a
reference to a single bitmap resource amongst several consumers, etc.

So maybe you're wondering why we don't just use global variables for these
kinds of things?  Well, you could, but global variables are "brittle" in the
sense that everyone has access to them.  By "wrapping" global resources in a
pool dictionary, and carefully defining where they can be accessed, we have
the opportunity to write less brittle code -- i.e. we have much greater
control over how the resources are allocated, used, etc.

Hope I didn't obfuscate the issue too much!  ;-)

Cheers,

---==> Chris



More information about the Squeak-dev mailing list