From: Lane S. <la...@op...> - 2003-07-21 23:47:41
|
I know where you are at about the statelessness and the object creation overhead. Based on what I have been reading, I think we should support all. 1) objects in the context on demand w/context (like the tool model). 2) static functions in the context on demand (we have this in global functions now) 3) static functions in the context on demand w/ a context argument.(your new proposal) I don't think one size will fit all. I fully recognize the value of statelessness, flyweight classes. Lane Keats wrote: >Lane, > >This is precisely the way context tools work now. The problem is that this >requires a new instance of the tool to be created for each request. If you >supply the context with each method call, the class becomes stateless and >therefore you only need a single instance (or no instance if you use static >methods). > >This is the way functional programming works. Generally, with object >oriented programming you store the state in object and this give you a clean >abstraction. However, in this case there is a performance hit with so much >object creation. By hiding the context argument from the script we can have >the best of both worlds to some extent -- a shareable stateless class, >without all the extra parameter passing. > >Keats > >----- Original Message ----- >From: Lane Sharman >To: Keats >Cc: Brian Goetz ; web...@li... >Sent: Monday, July 21, 2003 6:14 PM >Subject: Re: [Webmacro-devel] ContextTool improvements > > >Access to the Context is a terrific idea but isn't it better to something >like this: > > >class StatefulTool implements ContextStateful { > Context wc; > public void init(Context context) { // the ContextStateful interface > wc = context; > } > public String localize(java.util.Date date){ > return java.text.DateFormat.getDateInstance( > java.text.DateFormat.SHORT, > wc.getRequest().getLocale()).format(date); > } >} > > >When the class is references by the web script, its ContextStateful >interface is handled by the context class itself: > >if (tool == null) { > String toolClass = loadables.get(name); > Object o = Class.forName(toolClass).newInstance(); > if (o instanceof ContextStateful) { > ((ContextStateful) o).init(this) > } >} > >It seems to me that every method of a tool and its intance should have a >reference to the context on an explicit basis by declaring an init() method. >That, at least, is my take, Keats. > >-Lane > > > > -- Lane Sharman Learn About Conga, All Java GUI Builder: http://opendoors.com/conga Java Software Portal: http://opendoors.com |