i trying determine correct pattern handling calculated fields or methods in mvvm. have number of calculated fields required both presentation layer , end processing. let "calculatetotal" based on summing number of different values data object , sub objects.
i calculation in 1 location. first thought belongs in model (i.e., not viewmodel) since model object passed other end processing systems. best way make available viewmodel?
option 1, statically load viewmodel when create based off model (e.g., vwmodel.total = model.calculatetotal()) suffers if needing update viewmodel dynamcally, example modify underlying data , try new total.
option 2: more service oriented , each calculation calls service return values. issue see more performance based. once load object once, have data needed perform calculation. seems each call require data object reloaded
option 3: have viewmodel contain data model , create methods call data model methods
thoughts? suggestions?
i calculations in model. view model should subscribe events (e.g. via inotifypropertychanged) on model, when back-end values change, view model notified.
the view model can, of course, interrogate model calculations , doesn't have information through events. above when data changes come directly model or underlying data layer.
Comments
Post a Comment