I'm a beginner to Model-View-Presenter pattern and I'm finding a way to use it in a sample application
In my C# winforms application has a Employee Class
and it has properties like EmployeeID
,Name
, Address
, Designation
etc. Also it has behaviors like viewEmployee()
, AddNewEmployee()
, PromoteEmployee()
etc.
Could you please suggest how these things are organized in MVP pattern?
I have several entity classes in my project like
Employee
,Client
,Attendance
,Salary
etc. So should I make separateDataService
andPresenter
classes for each one?
My current understanding is like this...
Implementing ViewEmployee()----------
Class Employee
{
public string EmployeeID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Designation { get; set; }
}
Class EmployeePresenter
{
public void ViewEmployee(string employeeID, frmEmployeeDetails _form)
{
Employee Emp= EmloyeeDataService.GetEmployeeData(employeeID);
_form.txtName=Emp.Name;
_form.txtAddress=Emp.Address;
_form.txtDesignation=Emp.Designation;
}
}
Class EmployeeDataService
{
public static Employee GetEmployeeData(String employeeID)
{
//Get data from database
// Set Properties of Employee
//Return Employee
}
}
Partial Class frmEmployeeDetails : Form
{
btnViewEmployee_Click() //Button Event
{
EmployeePresenter.ViewEmployee(txtEmployeeID.text,this);
}
}