Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Im a beginner to Model-View-Presenter pattern and Im just trying to use it in a sample project for studies.

Lets say in my project (a c# win forms app) there is a `Employee Class` and it has properties like `EmployeeID`,`Name`, `Address`, `Designation` etc. Also it has behaviors like `viewEmployee()`, `AddNewEmployee()`, `PromoteEmployee()` etc.

1. Could you please advice me how these things are organized in MVP pattern?

2. I have several entity classes in my project like Employee, Client, Attendance, Salary etc. So should I make separate DataService and Presenter classes for each one?


My current understanding is like this...

**Implementing ViewEmployee()----------**

C#
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);
        }
    }
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900