From: Ben A. <ben...@ac...> - 2007-01-11 02:06:16
|
Hi We have a requirement to instantiate objects using complex constructors (not simply no-argument constructors). Essentially we will use parameter name discovery to retrieve the request parameter names from the constructor, then source the properties from the input object. We do this with Dozer quite successfully. InstantiatingReflector appears the appropriate Morph interface: public Object newInstance(Class clazz) throws ReflectionException; This is invoked by the BaseTransformer method: protected Object createNewInstanceImpl(Class destinationClass, Object source) throws Exception; I would like to request a change so that InstantiatingReflector is provided the source object, which we need in order to perform the desired destination object construction. ie: public Object newInstance(Class clazz, Object source) throws ReflectionException; I don't see this as a major problem, given that existing InstantiatingReflector implementations can simply ignore the additional parameter if they don't wish to use it. Alternately, if backward compatibility were an issue, could we have a new interface (InstantiatingSourceReflector?) which provided the interface, and have this new implementation extend InstantiatingReflector. Then BaseTransformer would detect the type of instantiating reflector injected and invoke accordingly. I realise we could simply override the BaseTransformer method, but then we force concrete inheritance to be used when a strategy pattern already exists and makes more sense. We just need the strategy to present the additional parameter. I'm happy to make this change and provide a patch, but I wanted to check which approach (or some other) that people preferred. Thanks Ben |