[Zope-PTK] Singletons
Shane Hathaway
shane@digicool.com
Thu, 10 Aug 2000 13:17:40 -0400
Kapil Thangavelu wrote:
>
> I was developing a python Product a python Product which basically acts
> like a Singleton object on a site to provide content. Content is stored
> within the Singleton. If content is referenced elsewhere on the site how
> do I find the Singleton? I'd like to access the Singleton Properties to
> configure the Content. Hardcoding is worthless if the Singleton moves.
>
> example (snip)
>
> if i allow access to Content only through Singleton accessor methods is
> the correct acquisition order preserved such that the Singleton is still
> in the acquisition context of Content?
The magic of acquisition makes it so that the correct acquisition order
is indeed preserved. There has been some discussion lately regarding
acquisition order--it's not obvious, so people don't trust it and want
to change it. But if you'll take the time to learn how acquisition
works, you'll find it's quite predictable, reliable, and fast.
So if you have a singleton that always has the same name, to find it
through acquisition you just use:
<dtml-var singleton_name>
Even though acquisition paths can be reordered through strange URL's,
acquisition always looks for objects in the containment path before the
context path. This makes it possible to depend on acquisition even for
security purposes.
I hope I've answered your question. :-)
Shane