DataSets and Table Module
There seems to be some confusion between DataSets and the Table Module Fowler PoEAA's pattern.
Fowler says a Table Module organizes domain logic with one class per table. Then he says that "the primary distinction with Domain Model is that, if you have many orders, a Domain Model will have one order object per order, while a Table Module will have one object to handle all orders", and that a single instance of a class contains the various procedures that will act on the data.
Fowler suggests that you could use a DataSet (RecordSet in his book) when you are using a Table Module, but that does not mean that every time you use a DataSet you are using Table Module, or that if you use custom classes you are not using Table Module. A lot of O/R mappers use Table Module with custom classes.
Lets see how we use DataSets in DeKlarit:
- One DataSet has more than one DataTable, with relations between them. For example, a master-detail relation.
- One DataSet usually has a specific instance of the data, for example, one Order, with header and lines. You can also have all the Orders and use them the way Fowler suggests, but it is used in the same scenario where in a domain model you have a collection of instances (like a CustomerCollection).
- Each DataTable in the DataSet does not map to a database table. For example, in the Order header I can have the Customer Name, so it maps to a join between Orders and Customers. In the Order details I can have the Product Description, the Product Price, so it maps to a Join between Orders Details and Products. The mapping between the DataSet and the real database tables is done by DeKlarit, and if a databse schema change implies a change in the way it should map it, DeKlarit will regenerate the corresponding code.
- You can have a complex process model that uses each DataSet. You usually dont have all the methods in one class, even if in DeKlarit there is a lot of logic running in the adapter, as you can add adding declarative rules to your entity and those business rules are triggered by the adapter when you try to persist the changes,
This approach does not follow any of the Table Module rules. There isnt a table per class, not all the data is loaded in the DataSet, and the logic is wherever you want.
So, DataSet != Table Module. The DataSet is just a standard interface to represent data that provides, for free, most of the things you could want to do with data. You can use it in any way you want.