|
From: Colin S. <col...@ex...> - 2004-07-21 12:22:57
|
Pavel, this already exists as child bean definitions. Take a look at section 3.5 in the docs below, http://www.springframework.org/docs/reference/beans.html on 'Child bean definitions' (for some reason the direct link to that subsection doesn't work). Note that this code is significantly enhanced in CVS over v1.0.2; to get the behaviour described in the manual above you need CVS code. Regards, Colin Pavel Tcholakov wrote: >Hi, > >This may have been discussed before, I did a Google search but nothing came >up. > >I was reading something on spring-user yesterday when it struck me, why do >we need to describe each and every property of each and every bean when we >have inheritance. Sure, this may not always be the best choice, but it would >make life easier in many cases and I would think it's relatively easy to >implement. > >Possible scenario: > >A hierarchy of DAO objects, all extending a base DAO, which in turn extends, >say, HibernateDaoSupport. Then instead of having in applicationContext.xml: > ><bean id="xyzDAO" class="com.mycompany.product.dao.hibernate.XyzDAO"> > <property name="sessionFactory"> > <ref local="mySessionFactory"> > </property> > <property name="somethingElse"> > <value>xyz</value> > </property> ></bean> > >for each and every DAO, you could just write something like: > ><bean superclass="com.mycompany.product.dao.hibernate.GenericDao"> > <property name="sessionFactory"> > <ref local="mySessionFactory"> > </property> ></bean> > >And then you could still have specific properties for those beans that >require it, like: > ><bean id="xyzDAO" class="com.mycompany.product.dao.hibernate.XyzDAO"> > <property name="somethingElse"> > <value>xyz</value> > </property> ></bean> > >Yay or nay? Seems to me it's a better way of dealing with generic properties >across the board and would make refactoring/plugging new implementations >easier? One could even take this a step further and implement property >setting based on regex on the bean ids or classnames much like the pointcut >definitions in the AOP module. > >Best regards, >Pavel > > |