Pragmatic Unit Testing in Java 8 with JUnit: Chapter 9, Other Design Thoughts, Visitor design pattern

Hello,

I’m having trouble seeing how the Visitor design pattern can improve the implementation of big-6/src/iloveyouboss/MatchSet.java. I understood the usefulness of the pattern in cases with polymorphism, but it is not the case here.

How avoid the performance penalty with double iteration in matches(), without going back to a single loop that does it all?

I appreciate if anyone can help clarify.

Best regards,
Hugo Lavalle