Welcome! and rules
Joel on Software
I've been struggling to find the optimal way to attach business rules to data. What is the general opinion, if any, of just subclassing a typed dataset and writing the business rules in the derived class?
Let's say I have a PersonData dataset, that contains tables for Person, Purchase, Payment and History. I could derive a Person class from that, and then add helper functions - for instance calculating their current balance (purchases minus payments), or creating History records for purchases and payments. And so on.
Right now, those kinds of calculations are happening in presentation code, and I'm in the process of refactoring them out.
My original plan was to use a Facade class. "Person" would contain the dataset instead of derive from it. It could provide the dataset, if databinding was desired, and it has the same kind of helper functions mentioned above.
Any thoughts as to which way is better? Anything better than either?
drowning in data
Wednesday, December 22, 2004
This sounds like a perfect candidate to use a framework.
CSLA.NET is a rich framework that does a lot of what you are looking for. The website is http://www.lhotka.net/ArticleIndex.aspx?area=CSLA%20.NET
There's also a tool called CodeSmith that does code generation based on ASP-like syntax. The URL is http://www.ericjsmith.net/codesmith/
I created my own framework, since I didn't need some of the fancier aspects of CSLA.NET like databinding and built-in business rules collections. I created several CodeSmith templates for my framework, and it's basically a point (to a database table) and click affair now.
Thursday, December 23, 2004
I use an object mapper to build the datasets from the objects, and the objects from the dataset.
The way I do it is mark the properties in my object with custom attributes to define which ones I need converted back and forth. Of course, I'm having to deal with a third party component where I don't have control over the incoming or outgoing structures, but it has worked extremely well for me.
I posted a blog entry giving the basic overviews of what I did to achieve it. If you want more information feel free to email me.
Cory Foy (cornetdesign.com)
Friday, December 24, 2004
Fog Creek Home