How to build the ViewModel in MVVM not to violate the Single Responsibility Principle?

后端 未结 4 1029
花落未央
花落未央 2021-01-17 12:15

Robert Martin says: \"There should never be more than one reason for a class to change\".

Let\'s consider the ViewModel class which is bound to a View. It is

4条回答
  •  天涯浪人
    2021-01-17 12:49

    I agree with gcores.

    Once you see ViewModel grow to more than two screenfuls of text, it is time to consider splitting ViewModel into several child models.

    Another rule of thumb is that I never have more than two levels of nesting inside XAML file -- if one part of the view becomes too complex, it is time for view refactoring -- extract inner XAML into separate UserControl and create corresponding ViewModel, which will be default data context on child view.

提交回复
热议问题