c# - internal relationship between properties -


my issue involves relationships , cascaded effects between properties, , i’m wondering best practices on this.

i have class contains list of varying length of numbers. when editing list, user prefer set targetsum, program enforces list add sum. accomplishing programmatically setting final element in list such list sum = targetsum. example, if user chooses usetargetsum, sets targetsum = 10, creates list of length 4, , enters 1, 4, 2 first 3 elements, final element programmatically fixed 3. user cannot change final element themselves.

i behind scenes handling necessary events, such list element value change, list length change, , usetargetsum option change. each event trigger, recalculates last element’s value.

it works there bug when loading saved data. if list loaded sequentially adding elements, handlers modify each entry. regarding example, when first value of 1 entered, handlers “a value added, sum should 10, there 1 element, needs 10”. first element gets changed 10 behind scenes. when second element next added, handlers “a value of 4 added, first element 10, should zero.” @ end of load, final list reads 10,0,0,0 instead of 1,4,2,3.

i know possible rearrange load procedure such correct list. instance, avoid enabling targetsum event handlers until after data loaded. list first created 1,4,2,3 , handlers change nothing.

but experience makes me wonder if opening door other sneaky side effects. seems should able load data without worrying implicit ordering. seems unusual have “cascading” effects between class properties. there more accepted approach?

the other alternative i’m considering enforce targetsum inside ui forms. ie, when know it’s user making change, enforce targetsum, otherwise leave core class logic alone. way database loads, etc, left unaffected. guess downside of not having ubiquitous enforcement opens door of incorrect sums via unforeseen complication.

first, make targetsum integer property in class. next, you'll need expand functionality of whatever manages list values loaded before manipulation of values in list.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -