協調 MVP 三元組 (Coordinating MVP triads)


問題描述

協調 MVP 三元組 (Coordinating MVP triads)

假設您的應用程序(WinForms .NET 2.0 應用程序)中有多個 MVP 三元組,每個三元組負責一個責任區域。您首選的協調 MVP 三元組之間通信的方式是什麼?

選項 1 一個協調器對象,它“擁有”每個模型並通過訂閱每個模型中的必要事件來負責協調,然後決定什麼模型在什麼場景下調用方法。

擔心這可能是“神”課。

選項2 一個Presenter“擁有”另一個Presenter,當模型中發生感興趣的事情時,Presenter使用另一個Presenter來推動交流。

擔心演示者不應該有一個公共界面(演示者優先方法),這打破了這一點。< /p>

我只是想知道其他人做了什麼來以可擴展的 OO 方式解決這個問題。如果我添加另一個 MVP 三元組會怎樣?將它融入我的協調器有多難?一定有一些很好的例子說明如何在一個 WinForms 應用中管理多個 MVP 三元組?


參考解法

方法 1:

Not to be vague... but it depends. The two approaches I've used in the past:

  1. Use an Event Aggregator pattern, and have the individual presenters fire off events that other presenters can handle. e.g. PresenterA does: events.Raise<MyEvent> () and PresenterB implements: IHandler<MyEvent> and reacts accordingly in its public void Handle (MyEvent @event) method.
  2. Use a shared model that is injected into the presenters that need to be coordinated. For example, if one presenter handles selection of a given Foo, and the other presenter needs to update a details panel with Foo details, I might use an IFooSelection state model and inject that into both presenters that need to coordinate the concept of 'current selection'.

The interface:

public interface IFooSelection {
    public event EventHandler Changed;
    Foo Selected { get; set; }
}

(by Peter KellyPete)

參考文件

  1. Coordinating MVP triads (CC BY‑SA 2.5/3.0/4.0)

#ooad #winforms #mvp






相關問題

接口實現是否應該獨立 (Should Interface implementations be independent)

當我們有不同的回報類型時實現策略模式 (Achieve strategy pattern when we have different return type)

抽象VS信息隱藏VS封裝 (Abstraction VS Information Hiding VS Encapsulation)

應用程序中jQuery表單綁定代碼的最佳實踐 (Best practices with jQuery form binding code in an application)

耦合與內聚 (Coupling and cohesion)

什麼時候應該在C ++中使用類與結構? (When should you use a class vs a struct in C++?)

What is an anti-pattern? (What is an anti-pattern?)

如何根據編程代碼顯示聚合? (How to Show Aggregation in terms of A Programming Code?)

協調 MVP 三元組 (Coordinating MVP triads)

裝飾器和虛擬方法 (Decorators and Virtual Methods)

設計和建築有什麼區別? (What is the difference between Design and Architecture?)

特定時間段有效的業務規則——如何有序管理 (Business rules that are valid for specific time span – how to manage in an orderly manner)







留言討論