MVVM: Should a VM object expose an M object directly, or only through getters delegating to M's getters?

后端 未结 4 2102
暗喜
暗喜 2020-12-23 11:35

the best way to explain is with example so:

this is the model

public class Person 
{
    public int age;
    public string name;
}

4条回答
  •  轮回少年
    2020-12-23 12:07

    Having a ViewModel for any Model could be worse than that. What if you have a hierarchical structure of a Model, or even a simple collection? In that case you'll have to iterate through all models and build a ViewModel instance per-model, and also to register notify-change events or other events. IMHO, this is completely insane, and unreasonable. As DaniCE said, you’ll end up with lot of code and a big headache.

提交回复
热议问题