[ http://issues.apache.org/jira/browse/IBATIS-50?page=comments#action_58247 ] Clinton Begin commented on IBATIS-50: -------------------------------------
I don't necessarily disagree with the idea of allowing factories, but I do disagree with the reasons and intended use. A few things: 1) Programming to interfaces is a best practice for services, behaviors, functions, etc. However, it is a horrible idea to program against interfaces to represent state. Why? Because it implies that there is more than one implementation of the behavior of the state (????). Doesn't make sense? Well it shouldn't, because it's an odd semantic. You should not have interfaces for your JavaBeans that represent state. Entity Beans are a perfect example of how ridiculous and problematic this design can be (session beans are a different story). 2) This entire request is contradictory. One of the complaints is that the "bean" must have a parameterless constructor. Well, that is more than acceptable since the JavaBeans specification requires this. That said, we are going to support parameterized constructors definable through result maps. 3) Factories are not the way to solve inheritance as described (yet another contradiction in this request --first a complaint, and then an intended use). We're going to support the <resultMap> <subclass> element, as in the .NET version of the framework. These new features will hopefully be available within the next 2 releases (2.1.0 or 2.1.1). Cheers, Clinton > Ability to override the default bean creation mechanism > ------------------------------------------------------- > > Key: IBATIS-50 > URL: http://issues.apache.org/jira/browse/IBATIS-50 > Project: iBatis for Java > Type: Wish > Components: SQL Maps > Versions: 2.0.9 > Reporter: Philippe Laflamme > > Currently, iBatis is responsible for creating instances of classes used in > result maps. It relies on the assumption that objects can be obtained using > the Class.newInstance() method (or something equivalent). > The assumption forces users of the framework to create classes with a no-arg > default constructor. IMHO, this also has the effect of favoring > implementation inheritance (extends) over interface inheritance. > Although this is not a problem in most cases, the ability to plug in an > external instance factory would provide more flexibility and favor good > programming practices. Amongst other things, it would provide developers the > ability write code in terms of interface. > A simple solution is to provide an extension point where resultMap class > instances are obtained from. > The simplest form would be: > public interface InstanceFactory { > Object createInstance(Class resultMapClass); > } > The default implementation would do something along the lines of: > [...] > return resultMapClass.newInstance(); > [...] > Developers could configure iBatis to either use the default implementation or > their own custom implementation. The setting could be part of the > sqlMapConfig file or even per resultMap. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira
