Reputation:
What is the use of the Transformer function in the apache commons collection ?
How do I use it in programs and at what times?
Upvotes: 4
Views: 597
Reputation: 1323823
Transformers
are function objects (also referred abusively as "software" functors, even though functor are a mathematical notion from the Category Theory).
They represent a function encapsulated in an object.
In most cases, the function’s parameters can be set and the result retrieved using the common accessors pattern, such as setParameter1(Object value)
or getResult()
.
The fact that these functions are encapsulated by real objects is also the reason for its greatest benefit: the use of many design patterns including structural ones such as the Decorator pattern and behavioral ones such as the Visitor pattern.
So you use Transformers
to apply a pattern on Collections, but also on other objects.
Here is an example of a creational pattern used through a Transformer.
Upvotes: 4