Microsoft
Software
Hardware
Network
Question : C# design question
Hi,
I have an application I have designed using the MVP pattern.
I have an application presenter which is fed into higher level presenters that are used for each view. There are some methods in the application presenter that I want to be able to expose to the views without exposing all of the application presenter. These methods also need to be called directly on the application presenter instance.
The way I have done this is to create an interface with the methods I want to expose. This interface is inherited and implemented by the application presenter.
I then created an abstract class whose constructor requires an instance of the interface. This abstract class is then inherited by each of the top-level presenters which in turn exposes them to the views.
Here is the code:
public interface ISwitchView
{
void SwitchToChartView(bool displayInModalDialogBox);
void SwitchToSaveModelResultsVi
ew(bool displayInModalDialogBox);
void SwitchToLoginView();
void SwitchToResultsView();
void SwitchToSaveLoadNetworkVie
w();
void SwitchToLaneClosureView();
void SwitchToLaneClosureView(La
neClosure lc);
void SwitchToTrafficVolumeView(
);
void SwitchToTrafficVolumeView(
VehicleInp
ut vi);
void CloseDialog();
void RenderNetwork();
}
public abstract class SwitchView
{
private readonly ISwitchView _controller;
public SwitchView(ISwitchView appPresenter)
{
_controller = appPresenter;
}
public ISwitchView View
{
get { return _controller; }
}
then, in the top level presenters I inherit SwitchView as follows
public class ResultsPresenter : SwitchView
{
private readonly ApplicationPresenter _controller;
public Presenter(ApplicationPrese
nter controller) : base(controller)
{
_controller = controller
}
Does all of this seem reasonable or is there a better way of doing it?
Thank you.
Answer : C# design question
OK, then, given what you've told me, I see nothing wrong with your approach, and I think you've made appropriate choices for your design. Do you have any other questions?
Random Solutions
Migrating shares from Windows 2003 to 2008
DC Promo fails to remove AD. NTDSUtil fails with "The connected server will not remove its own metadata."
Auto save and zip macro that overwrites zipped files when condition is met
Microsoft Project Server will not respond to requests for fully qualified domain names
Jump from main form into sun forms code in lost focus
How do I remove windows Encryption
how to count the number of browser tabs are opened for an application?
Backup of ESXi when no other Windows Server
How to open and close an excel file from Scheduled Tasks
Home folder quotas - best method?