Refactoring my simple model-view-presenter architecture My application uses a simple Model-View-Presenter architecture and uses the following classes and interface:

Presenter:

public abstract class Presenter&lt;V&gt; {

    private V view;

    public final void setView(V view) {
        this.view = view;
    }

    protected final V getView() {
        return this.view;
    }
}


View

public abstract class View&lt;V, P extends Presenter&lt;V&gt;&gt; implements ViewAdapter&lt;V&gt; {

    private final P presenter;

    public View(P presenter) {
        this.presenter = presenter;
    }

    protected final P getPresenter() {
        return this.presenter;
    }

    void initialize() {
        this.getPresenter().setView(this.asView());
    }
}


ViewAdapter

interface ViewAdapter&lt;T&gt; {
    T asView();
}


The application is then wired up like this:


A concrete Presenter is created.
A concrete View is created, passing in the concrete Presenter as a constructor parameter.
The View is initialised. During initialisation, the View calls the asView method to pass a view instance to the presenter.


Each concrete presenter in the application is parameterised with a view interface. Each concrete view class implements a view interface and can then pass itself to the presenter during initialisation and it is in this area that I am looking for advice.

The ViewAdapter interface exists solely to allow the concrete view to pass itself to the presenter via the asView method whilst maintaining type safety. My concrete views which derive from the View class are then forced to provide an implementation of the asView method in order to provide a view instance to the presenter that is of the correct type. 

Every implementation looks the same:

@Override
public FooView asView() {
    return this; // this implements the FooView interface.
}


All this basically does is force 'this' to implement FooView as I am unable to express something like this:

// Example, not valid code, won't compile!
public abstract class View&lt;V, P extends Presenter&lt;V&gt;&gt; implements V {
}


Which would allow me to remove the ViewAdapter interface and pass the view to the presenter in the abstract View class like this, removing the redundancy:

void initialize() {
    this.getPresenter().setView(this);
}
I tried it in an IDE and have some addition to the last comment. I agree that you should try 

Presenter&lt;V extends View&gt;


plus I would add that you need to switch the signature to 

public abstract class View&lt;V, P extends Presenter&gt; 


from 

public abstract class View&lt;V, P extends Presenter&lt;V&gt;&gt;


That is regarding to make it compile. Additionally, you can discard generics V since it is not used anymore in the View so the final signature would be:

public abstract class View&lt;P extends Presenter&gt;


Then you can get rid of ViewAdapter and the initialize method should work as you want it:

void initialize() {
    this.getPresenter().setView(this);
}