简体   繁体   English

异常和模型视图呈现器(C#)

[英]Exceptions and model-view-presenter (C#)

I have implemented the MVP pattern (passive view) in my C# Forms application. 我已经在C#Forms应用程序中实现了MVP模式(被动视图)。

In my case the model is a motor controller laser system, where the model actually is like a facade of two other models (one the motor control system, the other the laser system). 在我的情况下,模型是一个电机控制器激光系统,其中该模型实际上就像是其他两个模型的外观(一个是电动机控制系统,另一个是激光系统)。

My presenter is a mediator of model-events and methods to the view which handles the user interface. 我的演示者是负责处理用户界面的模型事件和方法的中介者。

Suppose my view has a setting for the laser power. 假设我的视图具有激光功率设置。 The user sets this to some value, which gets sent to the presenter, which in turn send the request to the model. 用户将此值设置为某个值,该值将发送到演示者,该演示者又将请求发送到模型。 If the laser power is out of range my model throws an error which get catched by my presenter. 如果激光功率超出范围,我的模型将引发一个错误,我的演示者会发现该错误。

How do I best mediate this message to the user? 如何最好地将此消息传达给用户? I thought about making, in my view, a method; 在我看来,我考虑过要制造一种方法。 HandleError(string message), and invoke this from the presenter. HandleError(字符串消息),然后从演示者中调用它。

This is my first project using MVP, so I haven't got the experience to say which way is the best way. 这是我第一个使用MVP的项目,因此我没有经验说哪种方法是最好的方法。

In the view, create a property for an Error Message. 在视图中,为错误消息创建一个属性。 From the presenter you can set the value of this property. 在演示者中,您可以设置此属性的值。 Back in the view on the setter for the property, store the value that's set as any typical property would do, but in addition add your logic for whatever the user interface needs to do. 返回该属性的setter的视图中,存储设置为任何典型属性都会执行的值,但除此之外,还要为用户界面需要执行的操作添加逻辑。 The View can then control the flow of what happens within itself. 然后,视图可以控制自身内部事件的流向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM