在C#中使用模型视图展示器 [英] Using model view presenter in C#

查看:220
本文介绍了在C#中使用模型视图展示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是模特 - 视图 - 演示者模式的初学者,我只是想在一个示例项目中使用它进行研究。



让我们在我的项目中说(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);
        }
    }

推荐答案

我从未参与过MVP所以查看这些文章

带有ASP.NET的模型视图演示者 [ ^ ]

构建适用于.NET的MVP框架。第1部分:MVC和MVP的基础知识 [ ^ ]

构建.NET的MVP框架。第2部分:实现核心功能 [ ^ ]
I never worked on MVP so check these articles
Model View Presenter with ASP.NET[^]
Building an MVP Framework for .NET. Part 1: The Basics of MVC and MVP[^]
Building an MVP Framework for .NET. Part 2: Implementing Core Functionality[^]


这篇关于在C#中使用模型视图展示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆