Sumant Tambe (17) [Avatar] Offline
#1
Why does
transformValues
takes a
ValueTransformerSupplier
(a factory) as opposed to just a ValueTransformer?

The code example in the book listing 4.6 passes a lambda that creates a new
PurchaseRewardTransformer
whereas the accompanying source code passes a previously created transformer object. The chapter does not explain which one should be preferred and why.
Bill Bejeck (44) [Avatar] Offline
#2
Hi Sumant,

Great question.

As for the
transformValues
taking a ValueTransformerSupplier vs. an instance of ValuesTransformer, I can't exactly say, but in my opinion, using a supplier offers more flexibility in building a topology.

From what I can see the text and the code match, both using a lambda to provide a previously created transformer. I think I updated the book and the change has not made it out to the latest MEAP yet.

As for using a lambda to create a new instance vs. passing in a previously created instance, I can't say one way is better, it's a matter of personal preference.

I made the change as I felt it increased the readability of the code to use the lambda to pass in the previously created instance vs constructing it within the lambda. Does that make sense?

Thanks for reading the book.

Cheers,
Bill