보기 상태의 ViewModel을 올바르게 인식하고 있습니다. 개념적으로 모델의 상태는 모델의 일부이지만 특정 시나리오에 따라 달라질 수 있습니다. 모델을 데이터라고 생각하십시오. 직렬화 할 수 있고 서버에서 가져올 수 있거나 데이터베이스에서 유지할 수있는/유지해야하는 것입니다.
예를 들어 장바구니가있는 경우 배송 카트의 항목이 분명히 모델의 일부입니다. 그러나 체크 아웃 과정 (지불 방법 수령, 지불 방법 확인, 사용자 확인)의 상태는 어느 쪽이든 갈 수 있습니다.
보일러 플레이트의 경우 합리적인 양의 보일러 플레이트로 잘 작동하는 패러다임은 ViewModel 내의 전체 모델을 포함하고 (실제로 #에서 참조) 모델의 모든 속성에 대한 getter 및 setter를 노출하지만, 적절한 균등 한 통보. 예 :
class PersonModel {
public string firstName { get; set; }
public string lastName { get; set; }
}
class PersonViewModel : INotifyPropertyChanged {
private PersonModel model;
// next 4 lines can be factored out to a BaseViewModel class
private PropertyChangedEventHandler PropertyChanged;
private raise(string propName) {
this.PropertyChanged(new PropertyChangedEventArgs(propName));
}
// ... repeat for each property in the model
public string firstName {
get { return model.fistName; }
set { model.firstName = value; raise('firstName'); }
}
public string lastName {
get { return model.lastName; }
set { model.lastName = value; raise('lastName'); }
}
}
출처
2013-04-19 07:31:55
Uri