MVVM - Flex 中的表示模型与 Silverlight 中的表示模型:优点和缺点?

发布于 2024-10-31 09:56:04 字数 719 浏览 0 评论 0原文

正如这里所说:

http://houseofbilz.com/archives/2010/12/29/cross-training-in-silverlight-flexmvvm-vs-presentation-model/

“如果您今天在 Google 上搜索“MVVM 和 Flex” ,第一篇文章的作者声称 MVVM 不适合 Flex,我完全不同意,Flex 框架使得在 Silverlight 中实现表示模型比类似的 MVVM 实现要容易得多。这并不是说没有好的第三方库可以让 Silverlight 变得更容易,而是在没有任何帮助的情况下,在 Flex 中更容易实现”

因此 MVVM 作为逻辑概念可以以两种方式实现。在 Silverlight 中实现比 Flex 需要更多的管道。

是什么阻止了 Silverlight MVVM 像 Flex 一样实现? Silverlight 在事件系统中不具有相同的功能来执行相同的操作吗?

如果是的话,为什么 Silverlight 会把事情做得更复杂,那么它的优点是什么?是关于使用更强类型的类接口吗?

还有什么缺点呢?例如,对于为 1 个视图模型实现多个视图,Flex 实现是否也使其变得更加明显?

As it is said here:

http://houseofbilz.com/archives/2010/12/29/cross-training-in-silverlight-flexmvvm-vs-presentation-model/

"If you do a Google search today for “MVVM and Flex”, the first post is by somebody who claims that MVVM is not a good fit for Flex. I couldn’t disagree more. Out of the box, the Flex framework makes it much easier to implement a Presentation Model than similar MVVM implementations in Silverlight. That is not to say that there aren’t good third-party libraries that make it easier in Silverlight, but without any help, it is easier to do in Flex. "

So MVVM as LOGICAL CONCEPT can be implemented in both but the way it is implemented in Silverlight requires more Plumbing than Flex.

What prevents Silverlight MVVM to be implemented like Flex ? Doesn't Silverlight have same capability in event system to do the same ?

If yes why does Silverlight do things more complicated what's the advantages then ? Is it about using Class Interfaces which are more strongly typed ?

What are the disadvantages also ? For example as for implementing MULTIPLE VIEWS for 1 View-Model does Flex implementation make it also more obvious ?

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

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

发布评论

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

评论(2

森林很绿却致人迷途 2024-11-07 09:56:04

是什么阻止了 Silverlight MVVM 像 Flex 一样实现?

在 .net silverlight/wpf 中,一切都应该透明。绑定是通知机制,因此它“至少”应该像事件库系统一样工作。

如果是,为什么 Silverlight 会这样做
比较复杂有什么好处
然后呢?

对我来说,这是关于心态的,如果我知道它是一个事件基础系统,那么我应该仔细使用它。不要过度使用它,等等。

案例:绑定转换器,很容易在flex中实现,而不是在silverlight中。

在flex中: text="{getColor(pm.customerName)}" 是的,这非常简单,但问题是你确定你的PM会被垃圾收集正确释放,因为它是一个事件基础系统,谁负责观察变化? getColor 方法?或 text 属性?或两者兼而有之?真的很难知道这一点。

在 silverlight 中: text="{Binding CustmerName, Converter={StaticResources nameToColorConverter}}" 我不需要问谁负责观察,因为 colorConverter 只是一个绑定支持的转换器。我不需要担心内存泄漏。

所以,对我来说,一切都与心态有关。

What prevents Silverlight MVVM to be implemented like Flex ?

in .net silverlight/wpf everything should transparent. Binding is notification mechanism so, it should act "at least" like event base system.

If yes why does Silverlight do things
more complicated what's the advantages
then ?

for me, it is about mindset, if i know it is an event base system, then i should carefully use it. do not over use it, etc.

cases: Binding converter, easily implemented in flex, not in silverlight.

in flex: text="{getColor(pm.customerName)}" yes it is amazing simple, but the question is are you sure your PM will be released correctly by garbage collection, because it is an event base system, who responsible to observe the change? getColor method? or text property? or both? really hard to know that.

in silverlight: text="{Binding CustmerName, Converter={StaticResources nameToColorConverter}}" i don't need to ask who is responsible to observe, because colorConverter is only a converter supported by binding. i don't need to worry about memory leak.

so, for me its all about the mindset.

一笔一画续写前缘 2024-11-07 09:56:04

实际上,有两件事使它变得更加复杂:

  • 实现 INotifyPropertyChanged
  • 命令

您可以在 Silverlight 中做的一件事是使用 “财产编织者”。它将执行类似于 Flex 中的 [Binding] 标记的操作,因为它会自动获取公共 getter/setter 并使用 INPC 模式重新编写它们。

至于命令,在 DelegateCommand 中包装方法被证明是大量的管道工作。有几种方法可以实现这一点。我喜欢基于约定的方法,在该方法中,您声明一个名为 Execute_Something 的公共方法,并且会自动创建命令 Something 供您绑定。 此处此处

最后,Flex 中的绑定是基于表达式的,而 Silverlight 中的绑定是纯粹声明性的。当我们获得 C# v.Next 时,我有一些想法,我们也许能够非常轻松地进行基于表达式的绑定。

There are two things, really that make it more complicated:

  • Implementing INotifyPropertyChanged
  • Commands

One thing you can do in Silverlight is use the "Property Weaver". It will do something similar to the [Binding] tag in Flex as it will automatically take public getter/setters and re-write them with the INPC pattern.

As for commands, wrapping methods in DelegateCommands proves to be a lot of plumbing. There are several approaches to this. I like a convention-based approach, where you declare a public method named Execute_Something and the command Something is automatically created for you to bind to. Here and Here.

Finally, binding in Flex is expression-based where as binding in Silverlight is purely declarative. I have some ideas for when we get C# v.Next and we might be able to do expression-based binding pretty easily.

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