[Seaside] Using Dynamic Bindings in Seaside rendering
Stephen Pair
stephen at pairhome.net
Mon May 12 00:56:43 CEST 2003
Here's an additional note on this topic...recently, I've been using the
following pattern when I have a situation that calls for a class
variable, but one which I want to allow to be overridden by a given
execution context. A good example of this is Project class>>current
(if, for example, you wanted to allow multiple projects to co-exist in a
single Squeak session). You can make an instance of a Project to be the
global default, while still allowing individual execution contexts to
override the default by providing accessor methods that look like:
Project class>>current
"Answer the project that is currently being used."
^#'Project-current' binding ifNil: [CurrentProject]
Project class>>current: aProject
"Set the project that is to be used in the current execution context."
#'Project-current' binding: aProject
To override the current project for a given block of code, do:
Bindings clamp:
[Project current: someProject.
self doSomething]
Lately, I've been using Symbols named after their class and method as a
experimental standard way of naming dynamic bindings. A nice attribute
of this approach is that a user of "Project current" doesn't care
whether or not a dynamic binding is being employed (or whether the
dynamic bindings framework is even present in the image).
- Stephen
More information about the Seaside
mailing list