c# - Can I create View and Presenter in different Project in MVP Pattern -


i learning mvp pattern current project(windows application). have work experience in mvvm using in silverlight , wpf. in mvvm view , viewmodel use in separate project , using strong binding of wpf use communicate each other. in mvp of example see in internet view , presenter in same project.

so questions are:- there way can create view , presenter in different project? mean view windows application , presenter class library project.

if yes then, how both view , presenter refer each other.

your presenter should ever communicate view via interface.

your presenter , view interfaces can contained in class library project windows application can reference. concrete views create in windows application project can implement appropriate view interface.

the simple example below shows how classes might interact.

classlibrary.dll

public class presenter {      // repository class used retrieve data     private irepository<item> repository = ...;      public void view { get; set; }      public void loaddata() {         // retrieve data repository or service         ienumerable<item> items = repository.find(...);         this.view.displayitems(items);     } }  public interface iview {     void displayitems(ienumerable<item> items); } 

windowsapplication.dll

public class concreteview : iview {      private button btn     private grid grid;     private presenter presenter = new presenter();              public concreteview() {         presenter.view = this;         btn.click += (s, a) => presenter.loaddata();     }      public void displayitems(ienumerable<item> items) {         // enumerate items , add them grid...     } } 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -