Hello everyone: Coming from VB6, I am still relatively new to the object oriented way of thinking. I have come up with a design that makes sense to me but unfortunately this is no guarantee that it makes sense. So I thought I would try to solicit comments to see if I'm out to lunch.
I am using the following design to edit and display a collection of records. Domain layer collection class: - has a DataTable field containing the original data pulled from the database. - has an ArrayList field containing new, deleted and modified records. - if a client requests a new record, an instance of a child object is created and added to the ArrayList. - if a client requests to delete or modify an existing record, the data is pulled from the DataTable and an instance of a child object is created and added to the ArrayList. - if a client requests to persist the changes, the ArrayList is sent by the domain layer to the data access layer. Client: The client recieves a copy of the DataTable from the domain layer and displays it in some sort of GUI list widget. (say a ListView) If the client wishes to modify or delete an item, it calls a method in the domain layer collection object, passing in a key. The collection object looks up the key in its copy of the DataTable and ,if the row exists, creates a new child object. If the client wishes to add an item, it calls a method in the domain layer collection object. The collection object creates a new child object and adds it to the ArrayList. The client then works with the objects in the ArrayList via an indexer. The three primary reasons I am doing this are as follows: 1) There is no encapsulation when a dataset is sent to the client. In many examples I have seen this does not appear to be an issue as domain objects will have a Save method that takes a dataset as a parameter and performs validation on that dataset only when received from the client. However, I often need to perform validation and provide a response as soon as the client has caused a change to a single field in a single object. Therefore I need an encapsulated object with a fine-grained interface. 2) Instances of child objects are only created when the client requests them. Therefore, I can avoid having to populate a collection with the all items in the DataTable unnecessarily. 3) The domain logic runs in the same process as the client, so a fine grained interface does not have the performance penalty that would exist if the logic were out-of-process. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.