With the MVVM pattern, I make the methods and properties the View binds to as public.
It feels like these should only be public for the view, and not anywhere else. Almost like a protected concept. But also, you want some public methods that can be used by other classes, so it gets kind of muddled.
I'm writing TypeScript so I could really access whatever methods/properties I wanted to, but in a language like C# I would guess you would have to expose viewodel properties as public for the view and truly have this issue.
ViewModel:
class viewModel {
private mode = "Editable";
// this is only meant for the view. but it's public so it could be tampered with.
public items = ko.observableArray();
// this is meant to be used by other code.
public setMode(mode) {
this.mode = mode;
}
private _datasvc = new someDataService();
constructor() {
this.items = this._datsvc.getItems();
}
}
Am I just not understanding or using MVVM correctly?
Aucun commentaire:
Enregistrer un commentaire