title: Visitor pattern implementation in case of source code un-availability
body: <p>One of the reasons to consider the <a href="https://en.wikipedia.org/wiki/Visitor_pattern" rel="noreferrer">Visitor_pattern</a>:</p>
  <blockquote>
  <p>A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures.</p>
  </blockquote>
  <p>Assume that you don't have the source code of third party libraries and you have added one operation on related objects.</p>
  <p>Since you don't have object, your elements (Third party classes) can't be modified to add Visitor.</p>
  <p><a href="https://i.stack.imgur.com/qPvAj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qPvAj.png" alt="enter image description here" /></a></p>
  <p>In this case, double dispatch is not possible.</p>
  <p>So which option is generally preferred?</p>
  <p><em><code>Option 1:</code></em>  Extend one more inheritance hierarchy on top of third party class and implement pattern as show in picture with double dispatch?</p>
  <p>For a given hierarchy of Class B which extends Class A, I will add</p>
  <pre><code>ElementA extends A
  ElementB extends B
  </code></pre>
  <p>Now ConcreteElements are derived from ElementA instead of class A.</p>
  <p>Cons: The number of classes will grow.</p>
  <p><em><code>Option 2:</code></em>  Use Visitor class a central helper class and get the work done with single dispatch.</p>
  <p>Cons: We are not really following Visitor patter as per UML diagram.</p>
  <p>Correct if I am wrong.</p>