From: Matt S. <Mat...@wh...> - 2007-04-22 04:03:41
|
Short answer: I think it's better to leave it protected in BaseTransformer and just override it to be public in ChainedConverter. Long answer: I don't think it’s appropriate for all transformers that extend from BaseTransformer to expose their source and destination classes as mutable properties. The source and destination classes are the contract that specifies what a transformer can do, and if an individual transformer wants to control this, it should be free to do so in a protected manner. An example of this would be the TextTransformer, which has a set number of text types it can handle. But what if a user were to want to change the behavior of TextTransformer so that there are more or fewer types it could handle? Well, to add a new text type to TextConverter it would be necessary to subclass TextConverter anyway to implement the transformation. There is a stronger case for removing capability, for example if you had your own converter you wanted to handle char[] -> String conversions and so wanted to limit the TextConverter’s functionality by reducing the source and destination classes. Both of these use cases are somewhat artificial though because there is an even simpler solution: just change the order of the transformers in your SimpleDelegatingTransformer so that it gets chosen before TextConverter is even tried. There certainly are cases where transformers want their source and destination classes to be public, and they can override the definition in BaseTransformer. BasePropertyNameCopier does this so that PropertyNameMatchingCopier and PropertyNameMappingCopier can be used for simple transformations without blocking other transformers from being used in a SimpleDelegatingTransformer. ChainedConverter sounds like another place where it’s reasonable to make the source and destination classes mutable. Matt S Matt Benson wrote: > I can't see a reason why we can't do this. One use > case I am seeing is with a ChainedConverter, being > able to set the source and/or destination classes on > the chain components helps to direct the flow of the > chained transformation. > > WDYT? > > -Matt B > |