C# MVP-谁创建了新模型?
我正试图在我当前的项目(Webforms)中实现MVP,这让我难以用语言表达 假设我有一个页面,我希望用户输入他的支付信息,然后将其发送到我的应用程序中的支付处理逻辑 假设付款信息如下所示:C# MVP-谁创建了新模型?,c#,asp.net,design-patterns,mvp,C#,Asp.net,Design Patterns,Mvp,我正试图在我当前的项目(Webforms)中实现MVP,这让我难以用语言表达 假设我有一个页面,我希望用户输入他的支付信息,然后将其发送到我的应用程序中的支付处理逻辑 假设付款信息如下所示: public class PaymentInformation { public BillingInformation BillingInformation { get; set; } public CreditCard CreditCard { get; set; } } public
public class PaymentInformation
{
public BillingInformation BillingInformation { get; set; }
public CreditCard CreditCard { get; set; }
}
public class BillingInformation
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string City { get; set; }
}
public class CreditCard
{
public string CardNumber { get; set; }
public string CVV { get; set; }
public int ExpirationMonth { get; set; }
public int ExpirationYear { get; set; }
}
视图应该这样做吗
public interface IPaymentView
{
string FirstName { get; }
string LastName { get; }
string Address { get; }
string City { get; }
string CardNumber { get; }
string CVV { get; }
int ExpirationMonth { get; }
int ExpirationYear { get; }
}
然后让演示者获取所有这些属性并创建实际的PaymentInformation实例
或者视图应该这样做
public interface IPaymentView
{
PaymentInformation PaymentInformation { get; }
}
在这种情况下,视图将从自己的控件中获取信息,并创建付款信息的实际实例,以便演示者可以使用它
我真的很困惑演示者应该如何从视图中获取“复杂”数据。在我看来,在MVP中,演示者是唯一一个真正“思考”的类 视图只是与用户交互的一种方式;向用户显示信息,并让用户输入信息 模型是将信息传递到任何需要的地方,或者更确切地说,演示者告诉它获取信息并传递。模型所做的就是存储数据 从我看来,您的视图似乎试图成为您的模型,而您的视图真正应该做的就是使用
btnSave\u Click(..)
方法,然后调用演示者运行适当的方法来存储/显示付款信息,然后告诉模型从视图/设置到视图
综上所述
更具体地回答你的问题:演讲者会。