协调 MVP 三合会

发布于 2024-10-03 10:24:36 字数 397 浏览 2 评论 0原文

假设您的应用程序(WinForms .NET 2.0 应用程序)中有多个 MVP 三元组,每个三元组负责一个职责领域。您协调 MVP 三人组之间沟通的首选方式是什么?

选项1 协调器对象“拥有”每个模型,并通过订阅每个模型中的必要事件来负责协调,然后决定在什么情况下调用什么模型方法。

担心这可能是一门“神”课。

选项2 演示者“拥有”另一个演示者,当模型中发生感兴趣的事情时,演示者会使用另一个演示者来推动通信。

担心演示者不应该有公共界面(演示者优先的方法),这打破了这一点。

我只是想知道其他人做了什么来以可扩展的面向对象方式解决这个问题。如果我添加另一个 MVP 三合会会怎样?将其融入我的协调器有多难?一定有一些很好的例子来说明如何在 WinForms 应用程序中管理多个 MVP 三元组?

Say you have multiple MVP triads in your application (WinForms .NET 2.0 app) and each triad looks after one area of responsibility. What is your preferred way of coordinating the communication between the MVP triads?

Option 1
A coordinator object that "has" each model and looks after the coordination through subscribing to the necessary events in each and then deciding what model methods to call in what scenarios.

Worry that this may be a "god" class.

Option 2
A Presenter "has" another presenter and when something of interest happens in the model, the presenter uses the other presenter to move communication along.

Worry that the presenters should not have a public interface (Presenter-first approach) and this breaks that.

I am just wondering what other people have done to solve this problem in a scalable OO fashion. What if I add another MVP triad? How hard will it be to fit that into my coordinator? There must be some good examples of how to manage multiple MVP triads in a WinForms app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带刺的爱情 2024-10-10 10:24:36

不要含糊...但这取决于情况。我过去使用过的两种方法:

  1. 使用 事件聚合器 模式,并让各个演示者触发其他演示者可以处理的事件。例如 PresenterA 执行以下操作:events.Raise() 和 PresenterB 实现:IHandler 并在其 public void Handle (MyEvent @event) 方法中做出相应反应。
  2. 使用注入到需要协调的演示者中的共享模型。例如,如果一个演示者处理给定 Foo 的选择,而另一个演示者需要使用 Foo 详细信息更新详细信息面板,我可能会使用 IFooSelection 状态模型并将其注入需要协调“当前选择”概念的两个演示者中'。

界面:

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

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; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文