From: Matt B. <gud...@ya...> - 2007-04-23 21:56:54
|
--- Matt Sgarlata <Mat...@wh...> wrote: > Short answer: I think it's better to leave it > protected in > BaseTransformer and just override it to be public in > ChainedConverter. Fair enough. In my use case I was thinking originally of the ubiquitous pattern of a TextToFoo converter that uses a TextConverter to magically get all its conversions and basically is a hand-run ChainedConverter with two components. Take two of these and pass to a chainedconverter, so that you have the ultimate transformation of FooToTextConverter, TextToBarConverter: Foo -> (text) -> Bar Here there are several classes that are both a valid destination for FooToText and a valid source for TextToBar. The current ChainedConverter implementation will take the first overlap it finds and be happy. But if it happens to choose Character or char data will be lost if the intermediate text representation is > 1 character long. I realized that for my immediate purposes I should simply override the setters in the TextToFoo/FooToText type classes. For something that might be usable out of the box, it seems like it might be appropriate to open access to these methods on ConverterDecorator and CopierDecorator for a reasonable way to wrap the bundled converters/copiers. WDYT? -Matt > > Long answer: > > I don't think its 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 TextConverters 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 its 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 > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 > express and take > control of your XML. No limits. Just data. Click to > get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > morph-developer mailing list > mor...@li... > https://lists.sourceforge.net/lists/listinfo/morph-developer > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |