I am creating an ASP.Net MVC application using the ViewModel approach so that my domain objects are separated from the “models” used by my user interface. To refer to ViewModel classes, I use the following convention. ViewModelName = ViewName + "ViewModel". For instance:
Index + ViewModel = IndexViewModel
So far, so good, this is a fairly common model, and there are a lot of recommendations on this topic in StackOverflow and elsewhere. My question is about child objects used by my ViewModels. If my ViewModel model requires a class with properties identical to my domain model object, I simply include the domain model in my ViewModel model. For instance:
public class PersonViewModel { public int PersonID { get; set; } public Address Address { get; set; } public string SomeOtherProperty { get; set; } }
However, I am not sure which naming convention should be used when I need a child with different properties from my domain model. For example, if the “Address” requires several additional properties, in addition to what is in the “Address Area” model, what should I name? I considered AddressViewModel as follows:
public class PersonViewModel { public int PersonID { get; set; } public AddressViewModel Address { get; set; } public string SomeOtherProperty { get; set; } }
but I just don't like it. My gut instinct is that the suffix ViewModel should only be for the top-level ViewModel.
I'm looking for suggestions from other developers about what naming conventions they use in this scenario, in particular, what would you call a child in this case?
source share