简体   繁体   中英

Exceptions and model-view-presenter (C#)

I have implemented the MVP pattern (passive view) in my C# Forms application.

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.

This is my first project using MVP, so I haven't got the experience to say which way is the best way.

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. The View can then control the flow of what happens within itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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