tags:

views:

121

answers:

1

I have been reading a lot on MVC/MVP patterns.... I have a simple question....If you have a view with loads of controls....say 10 texboxes and 10 checkboxes....etc etc... Am I expected to specify the properties and events each one of them in my IView interface?....

+2  A: 

Definitely not that way. Your IView Interface will define set of contracts/ methods (it includes properties) that can be accessed by your business layer. It is totally wrong to exposed your control in interface like this:


public interface IView
{
  TextBox UserNameTextBox{get;set;}
}

You should not have interfaces defined in this way. This is really a bad programming. You should rather expose some contracts that your UI layer will implement. E.g.


public interface IView
{
 public void SetUserName(string Text);
}

You can implement this interface on winform as well as webform.

Similarly, you are also not supposed to expose knowlede of UI in interface(Contract). Lets assume a scenario where you have to display information of Employee object on UI. You should pass Employee object to UI through this interface and UI will take care of way of representing this Employee object.
Your BL should never bother about n number of TextBoxes and checkboxes.


public class Employee
{ 
  //first name
  //last name
  //is manager
  //is teamleader
  //address
}

public interface IEmployeeView
{ 
  void SetEmployee(Employee employee);
}


public partial class EmployeeForm:WinForm,IEmployeeView
{
  public void SetEmployee(Employee employee)
  {
    ENameTextBox.Text = employee.FirstName+" "+employee.LastName;
  } 

}

Rakesh Gunijan