Sumant Tambe (16) [Avatar] Offline
Why does
takes a
(a factory) as opposed to just a ValueTransformer?

The code example in the book listing 4.6 passes a lambda that creates a new
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 (30) [Avatar] Offline
Hi Sumant,

Great question.

As for the
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.