簡體   English   中英

理解模型視圖演示(MVP)

[英]Understanding Model View Presentation (MVP)

我已經搜索了很多MVP,但我沒有找到任何有助於我理解它的好文章。 有沒有人知道關於這個主題的任何好文章,用現實世界的例子來幫助我更好地理解它?

提前致謝。

查看我對帖子的回答,這可能對您有所幫助:

ASP.net Model View Presenter值得花時間嗎?

它經歷了MVP和MVC之間的差異,因為兩者經常形成對比。
此外,還有一些有用的鏈接,展示了如何輕松地將MVP模型適用於現有的ASP.Net網站。

HTH

這是一個專門在asp.net上做mvp的網站: http ://webformsmvp.com/ MVP作為一種模式有點過時 - MVC(它有一個很棒的asp.net框架和支持)和MVVM(事實上的WPF模式)已經基本上接管了。 實際上,Martin Fowler(MVP的發明者)已經證明,該模式確實應該分為兩種模式:Passive View和監督控制器在他的網站上: http//martinfowler.com/eaaDev/ModelViewPresenter.html

如果您想更深入地了解這種模式,請查看Web客戶端軟件工廠2010工具。

此工具主要用於創建復合Web應用程序(模塊),但視圖是使用MVP模式實現的。 如果您要維護傳統的ASP.Net代碼,或者如果您想在ASP.Net范例中進一步挖掘,那么檢查此工具的源代碼是一個很好的起點。

此工具要求您安裝Visual Studio的幾個擴展,然后,您可以創建一個特殊的Web項目,為您實現MVP,它將向Visual Studio添加上下文菜單以方便任務

例:

  • 創建一個新項目

創建一個項目

  • 使用演示者添加視圖

使用演示者添加視圖

  • 檢查生成的文件

檢查生成的文件

  • 檢查默認生成的代碼:

      public partial class MyNewView : Microsoft.Practices.CompositeWeb.Web.UI.Page, IMyNewViewView { private MyNewViewPresenter _presenter; protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this._presenter.OnViewInitialized(); } this._presenter.OnViewLoaded(); } [CreateNew] public MyNewViewPresenter Presenter { get { return this._presenter; } set { if (value == null) throw new ArgumentNullException("value"); this._presenter = value; this._presenter.View = this; } } // TODO: Forward events to the presenter and show state to the user. // For examples of this, see the View-Presenter (with Application Controller) QuickStart: // } public interface IMyNewViewView { } public class MyNewViewPresenter : Presenter<IMyNewViewView> { // NOTE: Uncomment the following code if you want ObjectBuilder to inject the module controller // The code will not work in the Shell module, as a module controller is not created by default // // private IShellController _controller; // public MyNewViewPresenter([CreateNew] IShellController controller) // { // _controller = controller; // } public override void OnViewLoaded() { // TODO: Implement code that will be executed every time the view loads } public override void OnViewInitialized() { // TODO: Implement code that will be executed the first time the view loads } // TODO: Handle other view events and set state in the view } 

抓住工具的戰利品:

順便說一句,如果你要開始一個新項目,使用MVC應該是一個更好的主意,如果你需要編寫一個現有的應用程序,你可以在Web客戶端軟件工廠中作為MVP實現的基礎。

如果您感興趣,我認為有一個改進現有應用程序以使用Web客戶端軟件工廠的工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM