title: passing concrete factory into abstract factory class - java
body: <p>I'm creating a abstractFactory class and I want to be able to send the concrete factory as a parameter. This way I can remove the if/else chain inside my abstract class.</p>
  
  <p>My problem is I'm not sure how to typecast it back to the concrete class within my abstract class in order to call the createVehicle() method.</p>
  
  <pre><code>car = UniversalVehicleFactory.getFactory().createVehicle(CarFactory);
  plane = UniversalVehicleFactory.getFactory().createVehicle(PlaneFactory);
  </code></pre>
  
  <p>Inside UniversalVehicleFactory I have the method createVehicle which is the method I'm having a problem with. What I'm trying to achieve is: take the parameter, determine its class and cast it to that, then call its internal createVehicle class.</p>
  
  <pre><code>public Vehicle createVehicle(AbstractFactory factory) {
  
      // I want to take factory,
              // cast it to the concrete factory, and
              // call createMethod() on the factory 
  
      return factory.getInstance().createVehicle();       
  }
  </code></pre>
  
  <p>Help with this problem much appreciated!</p>