I am just starting to develop a C# winforms application which is to have a SQL back-end. I have classes for the user interface which allow the user to enter data. However there will also be validation, some options are conditional on other options, and on the forms there will be some read-only fields implemented using labels. A good example of the latter is when the user enters a discount rate and a price and it displays the discounted price.
I have business logic classes for the data objects. Would you:
- Instantiate these only at the point of saving and loading to/from the database, and hold state in the properties of the controls OR
- Keep the business logic objects constantly in memory and update them whenever the user enters/edits information?
Option 2 sounds like hard work as you have to handle everything changing on your forms. However, since you have an object in existence you can use that object to do the validation/calculations. You can call the DiscountedPrice
property, for example.