package try_ddd.try_ddd.javafxgui.javafxnofxml;

import try_ddd.try_ddd.javafxgui.javafxnofxml.views.View1;
import try_ddd.try_ddd.javafxgui.javafxnofxml.views.View2;
import javafx.scene.Node;

/**
 * Created by lucius on 12.05.17.
 */
public class ViewFactory {

    public AbstractView getView(Class viewclass){
        if(viewclass.equals(View1.class)) return new View1();
        if(viewclass.equals(View2.class)) return new View2();

        throw new IllegalArgumentException(String.format("%s not supported by %s",viewclass,getClass().getName() ));
    }

    public Node getNodeOfView(Class viewclass){
        return getView(viewclass).getRoot();
    }
}

@@ -187,16 +187,107 @@
 .Node;%0A%0A
+import java.lang.reflect.Constructor;%0Aimport java.lang.reflect.InvocationTargetException;%0A%0A
 /**%0A * C
@@ -400,143 +400,98 @@
 ass)
-%7B%0A        if(viewclass.equals(View1.class)) return new View1();%0A        if(viewclass.equals(View2.class)) return new View2
+ throws Exception %7B%0A        Constructor constructor = viewclass.getConstructor
 ();%0A
-%0A
         
 thro
@@ -490,114 +490,54 @@
     
-throw new IllegalArgumentException(String.format(%22%25s not supported by %25s%22,viewclass,getClass().getName() )
+return (AbstractView) constructor.newInstance(
 );%0A 
@@ -588,16 +588,34 @@
 ewclass)
+ throws Exception 
 %7B%0A      

use reflection instead of if statement