考虑某种带有 PimDetailVm 的个人信息管理演示,该演示将 Person 对象作为模型。该演示文稿将管理一个人的各个方面(姓名、联系点、地址等),这些方面加在一起会使原始视图模型膨胀。
所以我想为每个卫星视图模型分开。不过,原始视图模型仍然负责允许和提交更新,因此至少需要知道 IsDirty 和 IsValid 是否为 true,以及模型的当前状态。
干杯,
Berryl
更新
我原来的帖子中有太多文字;也许更好地组织这个会得到更多的回应并留下一些有用的东西,所以
父/子同步选项
- INPC
- 优点 - 已由虚拟机实现
- 缺点 - 多次触发,可以说应该仅限于数据绑定
优点
- 中介器
- 优点 - 意图清晰分离
- 缺点 - 不确定如何以通用方式实现和使用
优点
- 事件聚合器
- 优点 - 通用抽象
- 缺点 - 不确定如何以通用方式实现和使用
优点
- 域事件(即 PersonUpdated)并让模型成为同步源
- 优点 - 可以说该事件属于这里,简化了虚拟机基础设施
- 缺点 - 不确定
- 内部视图模型事件(即 ViewModelUpdated)
- 优点 - 比 INPC 更干净,因为它只发射一个并且其意图很明确
- 缺点 - 不确定
优点
- 硬链接(即 Parent.Update())
- 优点 - 意图明确,更容易调试
- 缺点 - 紧密耦合
优点
- 继承自依赖对象
- 优点 - Will 喜欢它
- 缺点 - 不可重用,与 WPF 调度程序紧密耦合
优点
- 从 DynamicObject 继承 VM
- 优点 - 您可以做您想做的事情
- 缺点 - 改变 ViewModel 结构,对于缺乏经验的程序员来说很复杂
优点
- 优点 - 做你想做的事情
- 缺点 - 学习曲线不明显
优点
Consider some sort of Personal Information Management presentation with a PimDetailVm that takes a Person object as it's Model. The presentation will manage various aspects about a person (name, contact points, addresses, etc), which together would bloat the original view model.
So I want to split off satellite view models for each. The original view model still has responsibility for permitting and committing updates though, so at a minimum its needs to know whether IsDirty and IsValid are true, and the current state of the Model.
Cheers,
Berryl
UPDATE
There is (was) too much text in my original post; maybe organizing this better will get more responses and leave a trail of something useful, so
Parent / Child synchronization options
- INPC
- Pros - already implemented by VM
- Cons - fires multiple times, arguably should be restricted for DataBinding only
- Mediator
- Pros - clean separation of intention
- Cons - not sure how to implement and use in a generic fashion
- Event Aggregator
- Pros - common abstraction
- Cons - not sure how to implement and use in a generic fashion
- Domain event (ie, PersonUpdated) and let the model be the synch source
- Pros - arguably the event belongs here, simplifies VM infrastructure
- Cons - not sure
- Intra View Model Event (ie, ViewModelUpdated)
- Pros - cleaner than INPC since it fires only one and its intention is clear
- Cons - not sure
- Hard link (ie, Parent.Update())
- Pros - intention is clear, easier to debug
- Cons - tight coupling
- inherit from Dependency Object
- Pros - Will likes it
- Cons - not reusable, tight coupling to WPF dispatcher
- inherit VM from DynamicObject
- Pros - you can do what you want
- Cons - changes ViewModel structure, complex to inexperienced programmers
- incorporate AOP with an interceptor
- Pros - do what you want
- Cons - learning curve, not obvious
发布评论
评论(1)
为了真正结束这个问题,Pete Brown 解决了这个问题的一些方面此处。
Josh Smith 在 MVVM Foundation 库 中还有两个非常有用的类来解决这个问题:Messenger 和 PropertyObserver。
Just to close this out really, Pete Brown addresses some aspects of this here.
Josh Smith also has two very useful classes in hi MVVM Foundation library that address this problem: Messenger and PropertyObserver.