Java Reference
In-Depth Information
Figure 2.2. Parameterizing the behavior of filterApples and passing
different filter strategies
Multiple behaviors, one parameter
As we explained earlier, behavior parameterization is great because it enables you to separate
the logic of iterating the collection to filter and the behavior to apply on each element of that
collection. As a consequence, you can reuse the same method and give it different behaviors to
achieve different things, as illustrated in figure 2.3 . This is why behavior parameterization is a
useful concept you should have in your toolset for creating flexible APIs.
 
Search WWH ::




Custom Search