title: Design Pattern to Merge Functionality of Two+ External Libraries
body: <p>I'm using two third party libraries to perform similar functionality. I need to be able to decide which library  to use at runtime (each one is superior at a different kind of task and I only know which one is needed for a specific task at runtime).</p>
  
  <p>I'm trying to create a single class so I could dynamically invoke the functionality of a specific library at run time. Initially, I thought of using the adapter pattern however the issue is that both libraries return different types of objects and the adapter pattern will only be useful if the interface (or signature) is the same.</p>
  
  <p>To provide a specific example, the <code>Selenium</code> framework allows me to extract a web element from a page by calling the method <code>driver.findElement(By.Xpath("XPath"))</code> on a <code>WebDriver</code> instance. Similarly, the <code>XSoup</code> framework (an extension of <code>JSoup</code>) allows me to perform the same functionality by calling <code>Xsoup. compile( "XPath" ).evaluate(doc ).getElements();</code>. The functionality of both methods are semantically equivalent  - however they both return (and expect) two different types of objects (<code>WebDriver</code> returns a <code>WebElement</code> and <code>XSoup</code> returns a instance of <code>Element</code> - two different objects. Similarly, <code>WebDriver</code> expects a <code>driver</code> object and <code>XSoup</code> expects a <code>document</code> object to be passed in as a parameter). </p>
  
  <p>My goal is to merge the functionality of the two frameworks by calling a single method (such as <code>getElement()</code> in this case) and let the method deal with the details of calling the correct library/framework (based on some parameter passed to the method for instance)</p>
  
  <p>What design pattern could be used to merge the functionality of both libraries at run time?</p>
  
  <p>Thanks</p>