How to better design it ???
- by Deepak
public interface IBasePresenter
{
}
public interface IJobViewPresenter : IBasePresenter
{
}
public interface IActivityViewPresenter : IBasePresenter
{
}
public class BaseView
{
public IBasePresenter Presenter
{
get;
set;
}
}
public class JobView : BaseView
{
public IJobViewPresenter JobViewPresenter
{
get { this.Presenter as IJobViewPresenter;}
}
}
public class ActivityView : BaseView
{
public IActivityViewPresenter ActivityViewPresenter
{
get { this.Presenter as IActivityViewPresenter;}
}
}
Lets assume that I need a IBasePresenter property on BaseView.
Now this property is inherited by JobView and ActivityView but if I need reference to IJobViewPresenter object in these derived classes then I need to type cast IBasePresenter property to IJobViewPresenter or IActivityPresenter (which I want to avoid) or create JobViewPresenter and ActivityViewPresenter on derived classes (as shown above).
I want to avoid type casting in derived classes and still have reference to IJobViewPresenter or IActivityViewPresenter and still have IBasePresenter in BaseView.
Is there a way I can achieve it ?