The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Sumant Tambe (17) [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 (47) [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.