View markup should be easy, right?
And implementing view models should also be easy, right?
And mapping it to our models should also be really easy?
So why do we struggle so hard?
Well, this is what a view model could look like in code. Really soon.
BTW: Address is also derived from ‘ViewModel’. Remember: Inheritance should be about behaviour, not state.
Follow me on @Bemafred.
public class Person : ViewModel
{
public string FirstName { get { return State.FirstName; } set { State.FirstName = value; } }
public string LastName { get { return State.LastName; } set { State.LastName = value; } }
[DependsOn("FirstName", "LastName")]
public string FullName { get { return "{0} {1}".Args(FirstName, LastName); } }
[DependsOn("FirstName", "Address.City")]
public string WhoLivesWhere { get { return "{0} lives in {1}".Args(FirstName, Address.City); } }
public Address Address { get; set; }
public Person() : this(null) {}
public Person(ViewModel parent) : base(parent) { Address = new Address(this); }
}