Hi,
I am currently working on this application(C#,WPF,LINQ2XML,.NET 4.0) that displays details for 'Animals'. An example of this would be the application displaying the types of Animals such as 'Birds','Mammals','Reptiles'. For each type of Animal, I will have sub-entries such as for 'Birds' I will have sub-entries like 'Sparrow','Hawk'; for 'Reptiles', I will have 'Alligators', 'Python'..etc..etc. The user will have the option to add comments for each of these sub-entries. An example would be for the sub-entry 'Sparrow', I will have an option to 'Add Comments'. Clicking on 'Add Comments' will pull up a textbox where the user can enter his or her comments for 'sparrow'. The user can insert multiple comments for a sub-entry. The user can have 1,2,3....n comments for 'Sparrow'. This will just entail clicking on 'Add Comments' multiple times.
The data is preloaded with information stored in XML files. I have separate XMLs for each Animal such as Birds.xml, Mammals.xml, Reptiles.xml. Each of these will have information regarding the sub-entries. Birds.xml will have XML fragments for 'Sparrow' and 'Hawk'.
I am using Linq2Xml to extract the information necessary to populate my animal objects(Model) which in turn are bound to the Presenter(I am using the Model-View-Presenter pattern) which is fed to the XAML.
I am successfully able to display the information from my XML in the view. The problem is with the 'Comments'.
There are two things that I need to achieve here:
Write all the comments added to a separate XML file (AnimalComments.xml) where I can store all the comments that have been added for all the sub-entries.
In case of an application failure, I would like this same XML file(AnimalComments.xml) to pre-populate all the comments that I entered before my application crashed.
In essence I am trying to serialize the state onto the disk but in reality I don't want the entire object graph to persist on the disk since I think I am going to add the feature of writing/adding to the AnimalComments.xml file whenever a comment is typed for a sub-entry and the focus is changed to some other sub-entry.
I was wondering if the collective wisdom of SO can help me with some elegant design guidance here to accumulate all the Comments added and persist them onto a disk in such a way that it can be used by the application later for a restore or to present in a human readable format. Any solutions requiring the use of an DBMS would not be pertinent in this situation since it is part of the requirement to store any data associated with the application on the local file system.
As Drake suggested below, there are ways to maintain the references to the Animals using some sort of Primary key but I am interested in how this should be tackled from an Object Oriented standpoint or if there are some prominent patterns that tackle this sort of a situuation.
Thanks