Skip to Content.
Sympa Menu

patterns-discussion - Re: [patterns-discussion] Singleton Pattern by John Vlissides

patterns-discussion AT lists.cs.illinois.edu

Subject: General talk about software patterns

List archive

Re: [patterns-discussion] Singleton Pattern by John Vlissides


Chronological Thread 
  • From: Pascal Costanza <pc AT p-cos.net>
  • To: Peter Sommerlad <psommerlad AT hispeed.ch>
  • Cc: patterns-discussion AT cs.uiuc.edu
  • Subject: Re: [patterns-discussion] Singleton Pattern by John Vlissides
  • Date: Mon, 3 Apr 2006 12:17:10 +0200
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/patterns-discussion>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>


On 3 Apr 2006, at 11:29, Peter Sommerlad wrote:

Hi James, hi all

Siddle, James wrote:
Hi Peter,
Could you recommend an alternative approach to singleton when applying cross
cutting concerns to legacy code?
Let me elaborate...the C++ project I'm currently working provides a nice
framework & general approach to accessing the current 'context', e.g. an
element sitting in the framework can get hold of a variety of objects via a
"framework context". This is an interface that is actually provided by the
overall framework container.
However, the project must also provide exception handling & logging to a
large quantity of legacy code...so we wrote a couple of singleton classes to
fulfil those roles. Are there any alternatives you could recommend to this
approach?
in a similar context we used a Context object passed through all method calls in the framework. This collected all globally needed information. There is also a pattern called Execution Context by Alan Kelly if I remember correctly, describing that mechanism.
see http://www.allankelly.net/patterns/#EncapsulateContext

And that's effectively a simulation of what some programming languages provide in the form of dynamically scoped variables. They can be understood as global variables, but without (some of) the disadvantages. For example, you can typically rebind such variables for the current thread without affecting other threads.

Dynamically scoped variables come in different flavors. In Common Lisp, they are called special variables - see http://p-cos.net/ documents/dynfun.pdf ; in Scheme fluid variables or parameter objects - see http://srfi.schemers.org/srfi-39/ ; in Haskell and C++ implicit parameters - see http://citeseer.ist.psu.edu/lewis00implicit.html and http://citeseer.ist.psu.edu/hanson01dynamic.html ; Perl has them, but I don't recall the details; in Java, they can be simulated with thread-local variables; etc.


Pascal

--
Pascal Costanza,
mailto:pc AT p-cos.net,
http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium








Archive powered by MHonArc 2.6.16.

Top of Page