Abstract / Interface design for user choosable window
<p>I have an app with a user configurable object, <code>MyObject</code>, which allows a user to choose a specific type of window to display at a later date. At this point the choices will end up as either a <code>DialogFragment</code> or a <code>FragmentActivity</code>.</p>

<p>The idea is that a later date when <code>MyObject</code> is called up, the app will display the Dialog / Fragment based on the option chosen in the configured <code>MyObject</code>. Essentially the functionality of both types of windows will be the same, just different presentations.</p>

<p>I started by creating an <em>abstract</em> class setup to do something along these lines</p>

<pre><code>public abstract MyDialog extends DialogFragment {
    private static mDialog;

    public abstract void close();
    public abstract void open();
    public abstract void start();
    public abstract void stop();

    public MyDialog (MyObject myO) {
        switch (myO.getDialogType()) {
            case 1: // MyDialog1
                mDialog = new MyDialog1(myO);
                break;
            case 2: // MyDialog2
                mDialog = new MyDialog2(myO);
                break;
        }

        mDialog.open();
    }
}

public MyDialog1 extends MyDialog {

    @override
    pubilic void onCreateDialog() {

    }

    // other implemented methods...
}

public MyDialog2 extends MyDialog {

    @override
    pubilic void onCreateDialog() {

    }

    // other implemented methods...
}
</code></pre>

<p>Where I am stuck is that I now am trying to add in the same heirachy with <code>ActivityFragment</code>, I can no longer extend <code>MyDialog</code>. I tried to have <code>MyDialog</code> extend <code>Fragment</code> and then child classes extend either <code>DialogFragment</code> or <code>FragmentActivity</code>, but that runs in to multiple-inheritance which can't happen.</p>

<p><strong>Is there a way to extend both types, <code>DialogFragment</code> and <code>ActivityFragment</code> from the same base class in my app?</strong></p>

<p>Should I instead do something more complex like this, using two case statements? I've never used this much in the way of abstraction, so am I incorrectly using it?</p>

<pre><code>public MyApp extends FragmentActivity {

    MyObject mMyO;

    public void someEvent() {
        if (mMyO.getDisplayType() == "Activity") {
            MyActivity myA;
            switch (mMyO.getType()) {
            case 1: // MyActivity1
                myA = new MyActivity1(mMyO);
                break;
            case 2: // MyActivity2
                myA = new MyActivity2(mMyO);
                break;
            }
            myA.open();
        }

        if (mMyO.getDisplayType() == "Dialog") {
            MyDialog myD;
            switch (mMyO.getType()) {
            case 1: // MyDialog1
                myD = new MyDialog1(mMyO);
                break;
            case 2: // MyDialog2
                myD = new MyDialog2(mMyO);
                break;
            }
            myD.open();
        }
    }
}

public MyDialog1 extends MyDialog {

    @override
    pubilic void onCreateDialog() {

    }

    // other implemented methods...
}

public MyDialog2 extends MyDialog {

    @override
    pubilic void onCreateDialog() {

    }

    // other implemented methods...
}

public MyActivity1 extends MyActivity {

    @override
    pubilic void onCreate() {

    }

    // other implemented methods...
}

public MyActivity2 extends MyActivity {

    @override
    pubilic void onCreate() {

    }

    // other implemented methods...
}
</code></pre>
