From: Marc P. <ma...@an...> - 2003-07-27 16:31:24
|
On Sat, 26 Jul 2003 22:34:34 -0400, Keats <ke...@su...> wrote: > Marc Palmer wrote: > >> >> public interface MyAppContextAwareObject >> { >> void init( o.w.Context ctx, MyApplication myapp); >> } >> > > We need to be a bit careful here; I think this construction could > encourage some concurrency problems. It seems to imply that you can > reuse the same instance across multiple requests/contexts, which you > cannot safely do. That example is just a trival interface to show that the approach I was suggesting confers us compatiblity and greater flexibility. If application X wants to use and interface like that shown above for their lazy variables they can, it's up to them. Of course sane people would not use and interface, and would instead do: public abstract class MyAppContextAwareObject { public MyAppContextAwareObject( o.w.Context ctx, MyApplication myapp) { ... } } Which solves your problem. The MyAppLazyVarFactory impl would just create objects of this type. > The factory (non-void) version implies that you are creating a new object > on each request that is initialized with the context, which is the way it > must be done to ensure thread-safety. Yes, but it's up to the app-writer what interface they use, and an approach like this - if they want to use it - means they don't need "two levels of factory", if you catch my drift. > This necessary object creation is precisely why I suggested the context- > aware function as more efficient alternative. I think context-aware functions are a completely separate idea, definitely with merit. Marc -- Marc Palmer Contract Java Consultant/Developer w a n g j a m m e r s java and web software design experts with an ethical outlook http://www.wangjammers.org |