GWT MVP 介绍问题

发布于 2024-11-18 17:28:07 字数 445 浏览 5 评论 0原文

我已经阅读了这里提出的很多 gwt-mvp 问题,但由于我对这种设计模式完全陌生,所以我想问一些问题:

[1] Activity-Place 模式与 mvp 是不同的模式吗?

[2] 在 MVP 模式中,演示者包含逻辑。现在小部件/控件的逻辑是在“活动”中定义的吗?

[3] CustomPlace 类是固定的(因为 Eclipse 插件构造它们)或者我可以放置数据/方法以及什么样的数据/方法?

[4] CustomView内部的Presenter接口有什么用?添加哪些数据/方法才有意义?

[5] 我想构建一个应用程序,该应用程序将使用许多将保存到数据库中的数据结构。我已经阅读了这里的其他一些文章,并且我会将 MVP 的模型部分放在每个活动中。所以我认为每次启动时创建每个活动的数据结构并加载其值(如果需要的话从数据库),并在用户进入另一个视图后更新数据库。您对这种方法有何看法?

I have read a lot of gwt-mvp questions that are asked here, but since i'm totally new to this design pattern I would like to ask some questions:

[1] The Activity-Place pattern is a different pattern than mvp?

[2] In the MVP pattern presenters contain the logic. Now the logic of the widgets/controls is defined in the Activities?

[3] The CustomPlace classes are fixed (as the Eclipse plugin constructs them) or can i put data/methods and what kind?

[4] What is the use of the Presenter interface inside a CustomView? What data/methods would make sense to add into it?

[5] I want to build an application that will use many data structures that will be saved into a database. I have read some other posts here and I will make the Model part of MVP live inside each Activity. So i think to create each time the data structures of each activity at start and load its values (if necessary from db) and will update the database after the user goes to another view. What do you think about this approach?

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

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

发布评论

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

评论(2

已下线请稍等 2024-11-25 17:28:07
  1. 首先让我们揭穿一个神话:活动/地点与 MVP 没有任何关系。 Places 是关于导航的,Activities 是关于将 UI 与 Places 一起“组件化”的。另一方面,MVP 是一种设计模式,它是关于如何组织代码的。

  2. 许多人将他们的活动用作 MVP 演示者,但这并没有得到强制执行。 GWT 团队正在尝试一种新方法,其中活动与演示者不同(如果您想了解那里发生的情况,则正在 mobilewebapp 示例中进行工作)。您还可以将您的活动作为您的视图,并使用“内部”演示者(类似于 Cell 小部件的工作方式)

  3. 地点或多或少是一个 URL。你可以在里面放任何你想要的东西。不过,我建议将地点设为不可变:构建一个地点,goTo 它,利用它的属性来构建您的 UI。

  4. 这就是 MVP 的事了。这仅需要解耦您的视图和演示者,主要是为了使单元测试中的模拟更容易(这尤其是视图界面,​​对于演示者界面来说并不多,除非为您的视图编写测试工具)。在某些情况下,您可能还希望对不同的演示者使用相同的视图;它们都将实现相同的接口,以便视图可以与它们对话。

  5. 关闭窗口/选项卡怎么样?我宁愿使用定期自动保存,或明确的保存按钮;并实现mayStop,以便在有未保存的更改时提示用户(类似于大多数桌面办公应用程序的工作方式,例如MS Word或LibreOffice,以及GMail,如果您尝试在邮件草稿被保存之前离开)自动保存)

  1. Let's start by debunking one myth: Activities/Places have nothing to do with MVP. Places is about navigation, Activities are about "componentizing" the UI wrt Places. On the other hand, MVP is a design pattern, it's about how to organize your code.

  2. Many people are using their activities as their MVP-presenters, but it's not enforced. The GWT team is trying a new approach where the activity is distinct from the presenter (work underway in the mobilewebapp sample if you want to follow what's going on there). You could also have your activity being your view and making use of an "internal" presenter (similar to how Cell widgets work)

  3. A Place is more or less a URL. You can put whatever you want in it. I'd suggest making places immutable though: build a Place, goTo it, make use of its properties to build your UI.

  4. That's about MVP then. This is only needed to decouple your view and presenter, mostly to make mocking in unit tests easier (this is particularly of the view interface though, not much for the presenter one, unless writing a test harness for you views). In some cases, you might also want to use the same view with distinct presenters; they'll all implement the same interface so the view can talk back to them.

  5. How about the closing of the window/tab? I'd rather use a periodic auto-save, or an explicit save button; and implement mayStop so it prompts the user when there are unsaved changes (similar to how most desktop office apps work —e.g. MS Word or LibreOffice—, and GMail if you try to navigate away before your mail draft is auto-saved)

む无字情书 2024-11-25 17:28:07
  1. Activity-Place 是该模式的一个实现。 Google 在 Google IO 上引入了 gwt-mvp 模式,但大约一年后才将其实现作为 GWT 的一部分提供。

  2. 是的活动包含业务逻辑。不,小部件/控件通常不包含任何逻辑,它们只是根据用户操作触发事件。对这些事件起作用的逻辑由用户编写并驻留在其他地方。

  3. 我不使用 Eclipse,所以不知道它生成的 Places。通常,自定义位置可以包含自定义字段和方法。例如,它们可以包含自定义地点标记参数,即如果地点标记是“#place:id1”,则您的自定义地点可以包含保存此参数的字段。

  4. 当View需要调用/访问Activity时,它通过Activity实现的Presenter来实现。例如,当用户在 for 中输入所有数据并按提交时,您可以在 Presenter 中使用一个名为 submit(formData) 的方法。

  5. activity.start(..)中准备/加载数据是一种正常的处理方式。如果经常使用特定的活动,那么您可能会考虑在适当的情况下缓存数据。

  1. The Activity-Place is an implementation of the pattern. Google introduced gwt-mvp pattern at Google IO, but only provided it's implementation as part of GWT about a year later.

  2. Yes Activities contain business logic. No, widgets/controls usually do not contain any logic, they just fire events based on user action. The logic that acts upon those events is written by user and resides elsewhere.

  3. I don't use Eclipse, so wouldn't know about Places generated by it. Normally custom Places can contain custom fields and methods. For example they can contain custom place token arguments, i.e. if place token is "#place:id1", than your custom Place could contain field holding this argument.

  4. When View needs to call/access Activity, it does so via Presenter, which Activity implements. For example when user enters all data in a for and presses submit, then you could have a method in Presenter named submit(formData).

  5. Preparing/loading data in activity.start(..) is a normal way of doing things. If particular activity is used a lot, then you might consider caching the data if appropriate.

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