General design questions

General design questions

Old forum URL: forums.lhotka.net/forums/t/4619.aspx


dmostert posted on Saturday, April 05, 2008

Hi,

I've got 2 general design questions.

1) If you hava a validation rule to check if an amount property (e.g. Investment Amount) is within a valid range, but the range also depends on other properties on the object, would you register the rule on each property that affects the range as well as the amount property? Or what other options exists?

2) If a child collection of this object needs to be notified / informed of the changed amount property (e.g. to update the  percentage split of the investment amount into a collection of selected funds), what is the best way to accomplish this? Should the parent as part of it's "setter" update the child collection, or should the child collection register a PropertyChanged event? Or, again, what other options exists?

I'm busy re-engineering a Delphi solution into C# .NET and I'm evaluating my current ideas / methods againts options that is available in .NET.

Thanks,
Dawid

JoeFallon1 replied on Saturday, April 05, 2008

For #1 - some of it depends on the user experience you are looking for. If you always want instant feedback then you should probably do things along the lines you described. If you want to set all the properties on screen first (like in a web form) and then only figure it out once they have all been posted you can do something like this:

Create a rule which is assigned to a dummy property - call it anything you want. "My Fake Account Property". Then you need to make sure this 1 rule is called whenever you call IsValid - so override it and call this rule first and then call MyBase.IsValid. This way the rule is only checked once when all properties are set rather than multiple times as each property is changed. This design also works well for screens where there are many checkboxes and your rule is that at least 1 of them must be checked.

Joe

 

 

JonnyBee replied on Sunday, April 06, 2008

Assuming you are using CSLA 3.0 I would 

1) Rules
A. Create a new rule inside my object to validate the field  and use ValidationRules.AddRule(...
B. Register Validationrules.DependantProperty from the amount property to the other properties that this rule depends on. This will assure that the ValidationRule is also executed whenever one of these properties are changed - You may even declare that the dependancy is bidirectional.  

2) Child collection
The simple solution is to call the method in the children from the property setter on your parent. Adding an event will require you to also recreate events in OnDeserialized on your object if you are going for n-tier business objects.

/jonny

dmostert replied on Wednesday, April 09, 2008

Thanks,

Both ideas basically confirm my own ideas...


Copyright (c) Marimer LLC