整个 GWT MVP 与 Activity 和 Places 的混淆
阅读了一段时间并观看了 Google IO 视频后,我仍然对 MVP 与 Activity 和 Places 的关系感到困惑。
我发现不久前发布了一个帖子 --> GWT 2.2 MVP 与 GWT 2.1 活动地点
“MVP 架构。MVP 是一个概念,实现它的方法之一是场所活动框架”
我还听到“演示者类似于活动”
我们可以给“没有 MVP 的活动和地点”
我们可以混合“有 MVP 的活动和地点”
“MVP 只不过是我们如何组织我们的项目,以便我们可以轻松地测试和组织代码”
然后我试图找出这样的东西 - > http://code.google.com/p/gwt-platform/
我我真的很困惑。我想要一个一站式线程来结束所有的混乱。
After reading a while and watching Google IO videos, I am still confused on how MVP relates to Activity and Places.
I found a thread posted a while back -->
GWT 2.2 MVP vs. GWT 2.1 Activities-Places
"MVP architecture. MVP is the concept, and one of the ways to do it is the places-activities framework"
I also hear "A presenter is analogous to an Activity"
We can gave "Activity and Places without MVP"
We can mix in "Activity and Places with MVP"
"MVP is nothing but how we organize our Project so that we can test and organize code easily"
Then I am trying to figure out stuff like this --> http://code.google.com/p/gwt-platform/
I am really confused. I would want a one stop thread to end all the confusion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
TL;DR:地点和活动与 MVP 没有任何关系。
地点是关于导航到您的应用程序:您从一个地方转到另一个地方。活动建立在地点之上,有助于将“您所看到的”与“您所在的位置”绑定在一起:
这些“部分”(区域)中的每一个都由
ActivityManager
进行管理,这些ActivityManager
监听PlaceChangeEvent
并询问其关联的ActivityMapper
哪个要在该区域显示的活动
。一切都与导航有关。
与 MVP 没有关系(不管官方文档怎么说)。不过,如果您使用 MVP,您可能会让您的活动成为“演示者”,控制“视图”(活动将传递回其
参数中接收到的
方法)。但这并不是一条规则,例如,Google 正在进行试验, mobilewebapp 示例,具有解耦活动和演示者。AcceptsOneWidget
的视图)启动TL;DR: Places and Activities are in no way related with MVP.
Places is about navigating into your app: you go from one place to another. And Activities builds on top of Places to help in binding "what you see" with "where you are":
Each one of these "parts" (region) are managed by
ActivityManager
s that listen toPlaceChangeEvent
s and ask their associatedActivityMapper
whichActivity
to show in that region.It's all about navigation.
There's no relationship with MVP (despite what the official docs say). If you use MVP though, you'll likely make you activities "presenters", in control of a "view" (the one the activity will pass back to the
AcceptsOneWidget
received in argument to itsstart
method). This is not a rule though, and, for instance, Google is experimenting, in the mobilewebapp sample, with decoupling activities and presenters.MVP 代表Model、View、Presenter,它是一种编码模式。它只是MVC(模型、视图、控制器)模式的演变。请参阅 MVC 维基百科页面。
MVP 和 MVC 的区别在于,在 MVP 中,模型和视图彼此不认识。在 MVP 中,你的观点应该尽可能愚蠢。所有的交互都由 Presenter 处理。这只是正确组织代码的一种方法。
有些人创建了框架来减少以这种方式组织代码所需的工作量。查看不同的 MVP 实现。在网上很容易找到它们。
MVP 使您的代码更易于测试,因为您可以轻松地用其他实现(通常是 Mock)替换您的视图,该实现将伪造行为或您的视图。因此,您不需要在浏览器环境中运行测试(GWT 视图是 HTML 视图)。所以你的测试会运行得更快。
谷歌文档说:
因此,Activities and Places 不仅仅是一个 MVP 框架。然而活动是演示者。
您可以使用演示者的“活动”界面,而无需使用地点和 Google 的其他对象。但在这种情况下,您可能应该编写一种自己的活动管理器,负责启动和停止您的活动。在启动和停止时,您可能想要创建视图,将其添加到 dom,注册事件处理程序等。当您停止时,您将希望销毁所有这些。
在其他一些 MVP 实现中,您可以找到具有相同作用的 bind() 和 unbind() 方法。
Google 的 Activity Place 实现的强大功能来自 Place 对象背后的所有对象,这些对象将使您的活动开始或停止并处理历史记录。
上面其他人提到的 地点 只是您 URL 的表示。
google 的 Activity Place 实现涉及到很多对象。这是一个帮助您理解的架构。您会发现该活动只是整个事情的一小部分。 您可以在本文中找到我的博客的更多详细信息
MVP stands for Model, View, Presenter, it is a coding pattern. It is just an evolution from the MVC (Model, View, Controller) pattern. See MVC wikipedia page.
The difference between MVP and MVC is that in MVP, the model and the view do not know each other. In MVP your view should be as dumb as possible. All the interactions are handled by the Presenter. It is just a way of organizing your code properly.
Some people have created frameworks to reduce the amount of work to do to organize your code this way. Have a look to different MVPimplementations. It is easy to find them on the web.
MVP makes your code easier to test as you can easily replace your view by an other implementation (usually a Mock) that will fake the behavior or your view. Thus you do not need to run your tests with a browser environment(GWT views are HTML views). So your tests will run faster.
Google documentation says :
So Activities and Places is much more than just an MVP framework. Nevertheless an Activity is a Presenter.
You can use the Activity interface for your presenters without using Places and other objects from Google. But in that case you should probably code a kind of Activity Manager of your own that will be responsible for starting and stopping your activities. In start and stop you probably want to create your view, add it to the dom, register your event handlers etc. And you will want to destroy all this when you stop.
In some others MVP implementations you can find bind() and unbind() methods that have the same role.
The power of the Activity Place implementation from Google comes from all the objects behind the Place object that will make your activity start or stop and that will handle history.
The Place as other people mentioned above is just a representation of you URL.
There are many objects involved in the Activity Place implementation from google. Here is a schema to help you understand. You will see that the activity is only a small part of the whole thing. You can find some more details on my blog in this article
活动是主持人。地点只是历史标记的包装。
混乱始于 Google IO 视频,其中介绍了 MVP GWT 概念,但没有给出实现。于是人们开始推出自己的产品。然后谷歌编写了 2.1 文档,其中详细介绍了这个概念,并且只提供了一些示例代码供下载。后来在 2.2 中,他们介绍了他们的完整实现,Activities 等。
因此,如果您想走 MVP 路线,您需要选择您的实现。活动可能是最好的,因为它是官方活动。
Activities are Presenters. Places are just a wrapper for history token.
The confusion began with Google IO video, where MVP GWT concept was introduced, but no implementation was given. So people started rolling their own. Then google wrote the 2.1 docs where they detailed the concept and only gave some example code to download. Later in 2.2 they introduced their full implementation, Activities et al.
So, if you want to go the MVP route you need to pick your implementation. Activites would be probably best, since it's the official one.
有两个独立的维度
设计模式
- 无图案
- MVP
导航和屏幕遍历
- 没有导航
- 活动和地点
您的应用程序可能遵循以下其中一项:
There are two independent dimensions
Design Pattern
- No pattern
- MVP
Navigation and screen traversal
- No navigation
- Activities and Places
You may have an application that can follow one of the following