Flex4 - 编码架构,视图/模型分离

发布于 2024-10-03 12:06:07 字数 192 浏览 4 评论 0原文

在我正在进行的项目中,我们刚刚开始使用Flex 4。我们不使用任何特定的框架,管理层需要一个完整的视图/分离架构。基本原则是每次将一个 ActionScript 类作为模型关联到 .mxml 视图。

我很难理解如何将两者联系起来:谁引用了谁,以及在我看来我可以在多大程度上消除脚本部分。

我真的很感激对此的任何见解。

谢谢

In the project I'm working on, we've just started to use Flex 4. We don't use any particular framework and management wants a full view/separation architecture. The basic principle is to associate each time an ActionScript class as a model to the .mxml view.

I'm having a hard time understanding how to link the two : who references who, and to what extent can I eliminate the script part in my view.

I'd really appreciate any insights on this one.

Thanks

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

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

发布评论

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

评论(2

千秋岁 2024-10-10 12:06:07

您还可以使用“表示模型”模式,这与 Silverlight 世界中的 MVVM 非常相似。不同之处在于,在 Flex 中,这非常容易,而 Silverlight 需要更多的管道。

架构是这样的:

  • 视图只是一个视图。所有声明性...很少的命令式代码
  • 表示模型 (PM) 包含 UI 行为并粘合到模型
  • 模型包含数据、服务和客户端业务规则

视图引用 PM 并使用数据绑定到 PM 中的属性。 PM 包装模型并添加 UI 级验证、UI 级行为和格式数据。

像 PM、MVC 和 MVP 这样的“分离的表示模式”对于以下“功能”非常重要:

  • 单元可测试性
  • 可设计性
  • 可维护性
  • 可移植性(浏览器到空中到设备...等)

You also have the ability to use the "Presentation Model" pattern, which is very similar to MVVM in the Silverlight world. The difference is that in Flex, it is VERY easy where Silverlight requires a ton more plumbing.

The architecture goes like this:

  • The View is just a view. All declarative... very little imperative code
  • The Presentation Model (PM) contains UI behavior and glue to the model
  • The Model contains the data, services and client-side business rules

The View references the PM and uses data binding to properties in the PM. The PM Wraps the Model and adds UI-level validation, UI-level behavior and Formats data.

"Separated Presentation Patterns" like PM, MVC and MVP are really important for the following "ilities":

  • Unit Testability
  • Designability
  • Maintainability
  • Migratability (Browser to Air to device... etc)
故乡的云 2024-10-10 12:06:07

通常,模型应该几乎不包含任何逻辑。视图包含显示模型提供的数据的逻辑。因此,视图访问模型,而不是相反。这也使得为同一组数据定义多个不同的视图成为可能。

在 Flex 中,数据绑定和内容提供程序都是将数据集成到 MXML 结构中的好方法。特别是数据绑定允许您只使用内容而无需考虑太多;尤其是不需要自己定义所有引用(因此您不需要在代码中编写这些引用)。

为了从视图中消除其余逻辑,通常在 MVC 架构中使用控制器。控制器是视图和模型之间的一些“中间人”,应该处理数据。因此您的应用程序使用的所有逻辑都应该在那里。这样,您就可以严格分离模型(仅包含纯数据)、视图(仅显示数据)和控制器(将它们全部组合在一起并在其间添加应用程序逻辑)。有关详细信息,请参阅维基百科文章。话题。

最后一点,有一些框架可以使 MVC 更易于管理。最著名的 ActionScript 可能是 RobotLegs

Usually, models are supposed to contain nearly no logic at all. Views contain the logic to display the data the models provide. As such a view accesses the models, and not the other way round. This also makes it possible to define multiple different views for the same set of data.

In Flex, data binding and content providers are both a good way to integrate data into the MXML structure. Especially data binding allows you to just use the content without thinking about it much; and especially without defining all the references yourself (so you don't need to write those in code).

To eliminate the rest of the logic from the view, you usually use controllers in the MVC architecture. Controllers are some "middleman" between views and models and are supposed to process the data. So all logic your application uses is supposed to be there. That way you have a strict separation of models (which only contain the pure data), views (which only display data) and controllers (which brings them all together and adds the application logic in between). See the Wikipedia article for further information on that topic.

And as a final note, there are some frameworks that make MVC easier to manage. Most known for ActionScript is probably RobotLegs.

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