Given a business object called “Rectangle” consisting of three integer properties “Width”, “Height” and a read-only “Area”.
Would you make the read-only “Area” property a full blown PropertyInfo property? If so, you would need to create a rule that sets this property value by multiplying “Width” * “Height” and have this rule run every time the “Width” or “Height” property are modified. Is the CSLA official way to do something like this? I guess that’s the way to go if you have to bind the property to some UI control but it just feels like such overkill to me.
Just want to make sure I am approaching this correctly.
I would say don't make it a propertyInfo unless you need a rule to be based on Area, otherwise a simple readonly property that multiples area x height would suffice.....
Obviously the more complex the readonly property, the more argument their is to effectively calculate on change and store in a propertyInfo.
In a WinForms app this would work fine with binding, cannot say what affect this would have in other UI technologies. Assume they require a PropertyHasChanged event to be raised to refresh? Anyone?
Surely, you could make a simple property and create a calculate method for calculate Area and raise OnPropertyChanged.
But in general terms I prefer my properties to be as simple as possible ("properties is not code") and create rules that does the calculation. Rules are generally easier to test and reuse and I prefer to make them as indepent as possible and independet of the actual BO.
Copyright (c) Marimer LLC