Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have been thinking about this a lot and I think I have a couple of possible solutions.</p> <ol> <li>Add a method to the view class to generate the subordinate dialog</li> <li>Create a factory that generates the model, view. and controller for the subordinate dialog</li> </ol> <h2>Method 1</h2> <pre><code>class ParentView extends JDialog implements IParentView { public IChildView newChildView(...) { return new ChildView(...); } // ... } interface IParentView { IChildView newChildView(...); // ... } class ParentController { private IParentView view; public ParentController(IParentView view) { this.view = view; } public void showChildView() { IChildView childView = view.newChildView(); ChildController childController = new ChildController(childView); childView.setVisible(true); } } class ChildView extends JDialog implements IChildView { // ... } interface IChildView { void setVisible(boolean visible); } class ChildController { private IChildView view; public ChildController(IChildView view) { this.view = view; } } </code></pre> <h2>Method 2</h2> <pre><code>// During testing, create a mock ChildFactory and assign it to instance class ChildFactory implements IChildFactory { private static IChildFactory instance; public static ChildFactory getInstance() { if (instance == null) { instance = new ChildFactory(); } return instance; } public static void setInstance(IChildFactory factory) { instance = factory; } public void createChild(IParentView parent) { IChildView view = new ChildView(parent); ChildController controller = new ChildController(view); view.setVisible(true); } } interface IChildFactory { void createChild(IParentView parent); } class ParentController { private IParentView view; public ParentController(IParentView view) { this.view = view; } public void showChildView() { ChildFactory.getInstance().createChild(view); } } // ParentView class similar to method 1 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload