// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class LibraryFactory {
   public static Foobar newFoobar(String letter) {
      Foobar res;
      try {
         res = (Foobar)Class.forName("Foobar" + letter).newInstance();
      } catch (InstantiationException e) {
         res = null;
         e.printStackTrace();
      } catch (IllegalAccessException e) {
         res = null;
         e.printStackTrace();
      } catch (ClassNotFoundException e) {
         res = null;
         e.printStackTrace();
      }
      return res;
   }
   public static void main(String[] args) {
      Foobar a = LibraryFactory.newFoobar("A");
      a.doit();
      Foobar b = LibraryFactory.newFoobar("B");
      b.doit();
   }
}
