This is my humble MVP solution and your specific problems.
First , all that a user can interact with or simply show is a view. Laws, behavior and characteristics of this kind are described by the interface. This interface can be implemented using the WinForms user interface, the console user interface, a web interface, or even without an interface (usually when testing a host) - a specific implementation simply does not matter if it obeys the laws of the presentation interface.
Second , viewing is always controlled by the presenter. The laws, behavior and characteristics of such a host are also described by the interface. This interface is not interested in implementing a particular view if it obeys the laws of its view interface.
Third , since the leader controls his presentation in order to minimize dependencies, there is really no benefit in the fact that the presentation does not know anything about its leader. There, a contract is concluded between the presenter and the point of view, which is indicated by the presentation interface.
Consequences Third :
- The host does not have any methods that the view can trigger, but there are events in the view that the host can subscribe to.
- The host knows his opinion. I prefer to accomplish this with a constructor injection on a particular presenter.
- The view has no idea that the host controls it; he will never be given any lead.
For your problem, the above might look like this in a slightly simplified code:
interface IConfigurationView { event EventHandler SelectConfigurationFile; void SetConfigurationFile(string fullPath); void Show(); } class ConfigurationView : IConfigurationView { Form form; Button selectConfigurationFileButton; Label fullPathLabel; public event EventHandler SelectConfigurationFile; public ConfigurationView() {
In addition to the above, I usually have a basic IView interface in which I put Show() and any view of the owner or title, which usually extracts my views.
To your questions:
1. When winform loads, it should get a treeview. Do I believe that the view should therefore call a method such as: presenter.gettree (), this, in turn, will delegate the model, which will receive data for the tree structure, create it and configure it, return it to the master, which , in turn, will move on to the view, which then simply assigns it, say, to the panel?
I would call IConfigurationView.SetTreeData(...) from IConfigurationPresenter.ShowView() , right before calling IConfigurationView.Show()
2. Will it be the same for any data management in Winform, since I also have a datagridview?
Yes, I would call IConfigurationView.SetTableData(...) for this. It depends on the form for formatting the data provided to it. The host simply obeys the viewing contract that he needs tabular data.
3. My application has several classes of models with the same assembly. It also supports a plugin architecture with plugins that need to be loaded at startup. Will the view simply call the presenter method, which in turn will call the method, which loads the plugins and displays the information in the view? Which level will then control the plugin links. Will the presentation contain references to them or the speaker?
If plugins are related to viewing, views should be aware of them, but not leading ones. If they are all associated with data and a model, then the view should have nothing to do with them.
4. Do I believe that a view should handle every thing about a view, from the color of the node tree, the size of the datagrid, etc.?
Yes. Think of it as a presenter providing XML that describes the data and presentation that takes the data and applies a CSS stylesheet to it. Specifically, the facilitator may call IRoadMapView.SetRoadCondition(RoadCondition.Slippery) , and the view then displays the road in red.
What about data for clicked nodes?
5. If, when I click on treenodes, I have to transfer a specific node to the leader, and then from the fact that the leader will determine what data he needs, and then asks the model for this data before presenting it back to the view?
If possible, I would transfer all the data needed to present the tree in one shot. But if some data is too large to transmit from the very beginning, or if it is dynamic in nature and needs a βlast shotβ from the model (via the presenter), I would add something like event LoadNodeDetailsEventHandler LoadNodeDetails to the view interface, so the host can To subscribe to it, LoadNodeDetailsEventArgs.Node details from the node in LoadNodeDetailsEventArgs.Node (possibly through your identifier of some type) from the model so that the view can update the displayed node data when the delegate event handler returns. Please note that asynchronous templates may be required if data sampling may be too slow for a good user experience.