[导入]Advantages and disadvantages of M-V-VM

I've had several questions about when and why to use M-V-VM versus other approaches.   The obvious purpose is abstraction of the View, reducing the amount of business logic or glue code stuck in code-behind.  All tasty goodness abstractly, but here's another concrete advantage:  the ViewModel is easier to unit test than code-behind or event driven code.  The ViewModel, though it sounds View-ish is really more Model-ish, and that means you can test it without awkward UI automation and interaction.  If you've ever tried to unit test UI code, you know how hard that can be.

Disadvantages?  For simple UI, M-V-VM can be overkill.  In bigger cases, it can be hard to design the ViewModel up front in order to get the right amount of generality.  Data-binding for all its wonders is declarative and harder to debug than nice imperative stuff where you just set breakpoints (though if you have lots of events running around, it may not be much different). 

Data-binding performance is quite good, but it does tend to create a lot of general book-keeping data around.  For awhile, we were adding a MultiBinding to every object we created.  Loading a large file this meant 50,000 of them.  In the WPF build we were using they were nearly 2K per...meaning the Bindings were heavier than the objects being bound.  In this particular case I replaced the all the Bindings with a single static callback and saved nearly 100MB...!  Normal UI won't create nearly so many bindings, but the perf is something to keep an eye on.


文章来源:http://blogs.msdn.com/johngossman/archive/2006/03/04/543695.aspx

posted on 2006-03-05 09:04 毒菇求Buy 阅读(199) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(7)

随笔分类(133)

随笔档案(111)

文章分类(65)

文章档案(53)

相册

收藏夹(30)

BLOG

Book store

Graphics Design

搜索

最新评论

阅读排行榜

评论排行榜