ViewModel Overview

I can either have items in the viewmodel (partial code):

public class PersonViewModel : INotifyPropertyChanged
{
    public string FirstName
    {
        get
        {
            return firstName;
        }

        set
        {
            firstName = value;
            OnPropertyChanged("FirstName");
        }
    }

    public string LastName
    {
        get
        {
            return lastName;
        }

        set
        {
            lastName = value;
            OnPropertyChanged("LastName");
        }
    }

}

      

or I can wrap them as DTOs inside the view model (partial mode):

public class PersonDTO : INotifyPropertyChanged
{
    public string FirstName
    {
        get { return firstName;}

        set
        {
            firstName = value;
            OnPropertyChanged("FirstName");
        }
    }

    public string LastName
    {
        get { return lastName; }

        set
        {
            lastName = value;
            OnPropertyChanged("LastName");
        }
    }

}

public class PersonViewModel 
{
    public PersonDTO boundToPerson;
}

      

which approach is better and why?

0


a source to share


1 answer


Assuming your model is essentially your DTO and not used anywhere. I would go with the first option.

This way you will just map your original entity to the model. In this case, the DTO is not required, since the model would be a flattened simple translation that you would use in your strongly typed representation.



Good luck!

+1


a source







All Articles