c# - MVP Pattern with WinForms - Proper way to access user input? -


i'm writing application using mvp pattern, , curious if there "correct" way pass user input view presenter.

for example, have simple search form text box , "search" button. in presenter, have function performs search , populates view result. in click event search button, call search function in presenter.

my question, preferred pass user input parameter search function in presenter, or better create accessor in view presenter retrieve user input?

example -

in view:

private void btnsearch_click(object sender, system.eventargs e) {     presenter.search(txtuserinput.text); } 

in presenter:

public void search(string userinput) {     //perform search } 

or

in view:

public string userinput {     { return txtuserinput.text; } }  private void btnsearch_click(object sender, system.eventargs e) {     presenter.search(); } 

in presenter:

public void search() {     string userinput = view.userinput;      //perform search } 

i implement using second approach.

presenter methods don't receive arguments , collect data iview.

as see it, view exposes state , behavior implemented in "stateless" presenter (the state reference view , injected dependencies).

this provides easy way unit test presenter against mock view, simple guideline when creating iview , presenter:

  • all data exposed through controls in ui should properties (usually valuetypes make winforms agnostic) in iview interface.
  • all behavior, such logic handling each button, , initialization should presenter methods.

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -