By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

What normally goes inside an interface for controller? (mvc)

P: 1
In mvc you separate view from controller. How do you do that in C#?

Many people define an interface for a controller but isn't controller is specific to a form(gui) which all controller contains is handle events from gui controls(button, treeviews, textboxes etc..) which you don't know until you code the form.

So is there a point in having an interface for a controller where that controller is tightly tied to a specific form.

Having said that, many people say that controller can be used with many forms - how? as i'm aware of is controller tied to specific gui controls (like is said above).

Basically what i think a controller is for handling gui events and that is depending on gui controls. am i correct?

If not, what is the correct way to do it? what goes inside interface for controller?

thanks in advance
Aug 19 '09 #1
Share this Question
Share on Google+
1 Reply


P: 74
Hi Robert,

Windows application.
Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form, IUserView
  2.     {
  3.         UserViewPresenter _presenter;
  4.  
  5.         public Form1()
  6.         {
  7.             InitializeComponent();
  8.             _presenter = new UserViewPresenter(this);
  9.             _presenter.SetCustomerData();
  10.         }
  11.  
  12.         private void Form1_Load(object sender, EventArgs e)
  13.         {
  14.         }
  15.  
  16.         #region IUserView Members
  17.  
  18.         public string FirstName
  19.         {
  20.             set { firstname.Text=value; }
  21.         }
  22.  
  23.         public string LastName
  24.         {
  25.             set { lastName.Text = value; }
  26.         }
  27.  
  28.         public string Address
  29.         {
  30.             set { address.Text = value; }
  31.         }
  32.  
  33.         public string City
  34.         {
  35.             set { city.Text = value; }
  36.         }
  37.  
  38.  
  39.         public string ErrorMessage
  40.         {
  41.             set
  42.             {
  43.                 errorLabelMessage.Text = value;
  44.                 errorLabelMessage.Visible = value != "";
  45.             }
  46.         }
  47.  
  48.         public string SearchCriteria
  49.         {
  50.             get { return searchCriteria.Text; }
  51.         }
  52.  
  53.         #endregion
  54.  
  55.         private void searchButton_Click(object sender, EventArgs e)
  56.         {
  57.             _presenter.SetCustomerData();
  58.         }
  59.  
  60.     }
  61.  
Asp.net Application
Expand|Select|Wrap|Line Numbers
  1. public partial class _UserView : Page, IUserView
  2. {
  3.     private UserViewPresenter _presenter;
  4.  
  5.     protected void Page_Load(object sender, EventArgs e)
  6.     {
  7.         _presenter = new UserViewPresenter(this);
  8.         _presenter.SetCustomerData();
  9.     }
  10.  
  11.     protected void searchButton_Click(object sender, EventArgs e)
  12.     {
  13.         _presenter.SetCustomerData();
  14.     }
  15.  
  16.     #region IUserView Members
  17.  
  18.     public string FirstName
  19.     {
  20.         set { firstName.Text = value; }
  21.     }
  22.  
  23.     public string LastName
  24.     {
  25.         set { lastName.Text = value; }
  26.     }
  27.  
  28.     public string Address
  29.     {
  30.         set { address.Text = value; }
  31.     }
  32.  
  33.     public string City
  34.     {
  35.         set { city.Text = value; }
  36.     }
  37.  
  38.     public string ErrorMessage
  39.     {
  40.         set
  41.         {
  42.             errorMessageLabel.Text = value;
  43.             errorMessageLabel.Visible = value != "";
  44.         }
  45.     }
  46.  
  47.     public string SearchCriteria
  48.     {
  49.         get { return searchCriteria.Text; }
  50.     }
  51.  
  52.     #endregion
  53. }
  54.  
From above code we learn that we seperate out User Interface from Data.
so that same middle layer i.e. business logic need not to be change.
Aug 24 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.