I am trying to create several classes for managing a sample presenter application. I came up with the following definitions, but I try to avoid recursive generics.
public abstract class Presenter<V extends View<...?>> {
protected V view;
public Presenter(V view) {
this.view = view;
}
}
public abstract class View<P extends Presenter<...?>> {
protected P presenter;
}
I wanted to establish a relationship between the two classes. The idea was that I could create a presenter for a specific presentation, both classes relying on useful methods defined in abstract base classes, but both know exactly which subclass the abstract abstract class is used for.
My problem is defining a piece of code ..?. I see no way to avoid a recursive situation, for example:
public abstract class View<P extends Presenter<V>, V extends View<Q>, Q extends...>
and even this definition is consistent, since the View class now accepts two common parameters ... massive confusion.
, , , :
public abstract class Presenter {
protected View view;
public Presenter(View view) {
this.view = view;
}
}
public class FooPresenter extends Presenter {
public FooPresenter(BarView view) {
super(view);
}
public someMethod() {
((BarView) getView()).viewSpecificMethod();
}
}
, "" .