Is there some way to solve my code below? I’m kinda stuck.
How can I use a factory to create generic presenters, is it even possible without a non generic base class?
public abstract class Presenter<T>
{}
public SomePresenter : Presenter<ISomeVew>
{}
public SomeOtherPresenter : Presenter<ISomeOtherView>
{}
public class Factory()
{
public ??? CreatePresneter(int runTimeValue)
{
if (runTimeValue == 1)
return new SomePresenter()
else
return new SomeOtherPresenter()
}
}
Many times generic base classes need non-generic bases, so write
and use
PresenterOffor your presenters.Then
CreatePresentercan returnPresenter. Obviously, this only helps ifISomeViewandISomeOtherViewhave a base class that Presenter can work on.If these views and presenters don’t have commonality in the interface, then using one factory to make them all might not make sense.