What would your strategy for splitting a form between logic and database record management?
I’m honestly asking, because that’s what I’m thinking about today.
I’m thinking in terms of creating tests a la TDD style work. Having business logic that you could separate completely from needing database records for testing.
I’ve always liked binding forms to a datasource. The form handles data persistence well this way because as changes are made to bound controls they get saved to a database table and are therefore persistent. In my career, I’ve always dealt with form events such as clicking on buttons, updating controls, and the various events that happen on the form and intertwined them with business logic.
But what if I was able to abstractly represent the data layer separately so that persisting it and making business decisions and changes to it were separate functions.
For example, and this is literally off the top of my head, what if I read all the data stored in controls on the form into a dictionary, or even a class or set of classes to represent the data. Like an Order Class and an Order Lines Class for example. The order class could store all the information for an order and a collection of order line classes related to that order.
I know there are folks out there who have built classes to write a new class based on a table so you can completely abstract your data. I used to think this was overkill, BUT, it does allow for certain benefits.
When testing for example, you could create an instance of the classes with the exact test data you need without having to worry about the state of a form or interacting with the database, which is slow. You could run all your business logic tests using these objects. Then the objects could have “Save” or “Load” methods to save the record to the database or retrieve it.
Theoretically, your application logic could be completely separate from the database and you could then migrate your application logic to a different platform easily and just have to create a new data persistence module for a new back end.
Trackbacks/Pingbacks