Violation of Model-View-ViewModel with DRY?

I read this article today http://dotnetslackers.com/articles/silverlight/Silverlight-3-and-the-Data-Form-Control-part-I.aspx about using the MVVM template in a silverlight application where you have domain entities and views that are basically a subset of the objects of a real object. Is this not a clear violation of the DRY principle? and if so, how do you handle this glorious way?

+5
source share
4 answers

Personally, I don’t like what Dino does there, and I would not approach the same problem. Usually, I think of a virtual machine as filtered, grouped, and sorted collections of model classes. VM for me is a direct comparison with the view, so I can create a NewOrderViewModel class that has several CollectionViews used by View (maybe one CV for clients and another CV for products, maybe both filtered). Creating a completely new VM class for each model class really violates DRY, in my opinion. I would prefer to use derivation or partial classes to increase the model if necessary by adding specific (often calculated) properties to the View. IMO.NET RIA Services is an excellent implementation of combining M and VM data with an added bonus,which can be used both on the client and on the server. Dino is a brilliant guy, but a way to name him on that.

+7

DRY - , . . . DRY , . , , 0.

: DRY . , , - . .

+2

, , , , ViewModel. ViewModel , .

, - ViewCategoryViewModel . Category ViewModel ( "SelectedCategory" ), , , , .

There will always be some similarities between the domain model and the view model, but it all comes down to how you decided to create the ViewModel.

+1
source

Same as with Data Transfer Objects (DTO).

the domain for these two types of objects is different, so this is not a violation of DRY .

Consider the following example:

class Customer
{
    public int Age
}

And an example view model:

class CustomerViewModel
{
    public string Age;

    // WPF validation code is going to be a bit more complicated:
    public bool IsValid() 
    {
        return string.IsNullOrEmpty(Age) == false;
    }
}

Differential domains - types of differnet properties - different objects.

+1
source

All Articles