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:[EMAIL PROTECTED], http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium




_______________________________________________
patterns-discussion mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/patterns-discussion

Reply via email to