问题描述
我是模特 - 视图 - 演示者模式的初学者,我只是想在一个示例项目中使用它进行研究。
让我们在我的项目中说(ac #win forms app)有一个`Employee Class`,它有`EmployeeID`,`Name`,`Address`,`Designation`等属性。它还有`viewEmployee()`,`AddNewEmployee()等行为。 ,`PromoteEmployee()`等
1.你能否告诉我这些东西是如何以MVP模式组织的?
2.我的项目中有几个实体类,如Employee,Client,Attendance,Salary等。那么我应该为每个实体课程分别创建一个DataService和Presenter课程吗?
我目前的理解是这样的...
**实施ViewEmployee()--- ------- **
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()----------**
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);
}
}
推荐答案
这篇关于在C#中使用模型视图展示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!