Note that there are some explanatory texts on larger screens.

plurals
  1. POMVP: 3rd party controls, How much logic can be put in View layer
    text
    copied!<p>I'm learning MVP pattern, but still have some doubts.</p> <p><a href="http://www.martinhunter.co.nz/articles/MVPC.pdf" rel="nofollow">Martin Hunter</a> in his MVC/MVP overview wrote:</p> <blockquote> <p>In MVP, the view becomes an ultra-thin component whose purpose is purely to provide a presentation to the user. The view catches and handles events raised by the user, but forwards these directly to the presenter who knows how to deal with them.</p> <p>(...)</p> <p>However, with MVP the view catches events raised and forwards them to the controller (presenter)</p> </blockquote> <p>This is fine with buttons and text boxes, but what in case there are some more complex controls? Lets say I'm using 3rd party components, like Devexpress's TreeList control. Assume I want to dinamically build sub-nodes when user clicks expand button "+". Not using any pattern I could code this like that:</p> <pre><code>private void BeforeExpand_EventHandler(object sender, BeforeExpandEventArgs e) { TreeList treeList = sender as TreeList; MyModelObject nodeObj = e.Node.Tag as MyModelObject; treeList.BeginUnboundLoad(); //Create sub-nodes depending on nodeObj treeList.EndUnboundLoad(); } </code></pre> <p>As you can see there are some View-objects, like BeforeExpandEventArgs, TreeListNode, some specific actions like BeginUnboundLoad(), and so on. In that case my View layer cannot be "ultra thin". I cannot pass directly to Presenter objects like BeforeExpandEventArgs because it would affect the Presenter with some View stuff. </p> <p>My question is then: <strong>How much logic I can put into View layer</strong>? For example, is code presented below ok? </p> <pre><code>private void BeforeExpand_EventHandler(object sender, BeforeExpandEventArgs e) { TreeList treeList = sender as TreeList; MyModelObject nodeObj = e.Node.Tag as MyModelObject; treeList.BeginUnboundLoad(); e.Node.Nodes = this.presenter.GetNodes(nodeObj); treeList.EndUnboundLoad(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload