Question about how to keep an object updated
If I have a complex object that is originally created from say an XML document that has a few layers and provides our application status over a network.
-public Ears ears
-public Eyes eyes
-public Teeth teeth
-publig Nose nose
-public Chin chin
-public CreateHead(XML <head>)
new Head h
h.Ears = new EarsFactory(<ears></ear></ear></ears>);
h.Eyes = new EyesFactory<<eyes></eye></eye></eyes>);
h.Teeth = new TeethFactory(<teeth></tooth></tooth></teeth>);
h.Nose = new NoseFactory(</nose>);
h.Chin = new ChinFacotry(</chin>);
class Ears (Generic Collection)
-public CreateHead(XML <ears>)
class Eyes (Generic Collection)
-public CreateHead(XML <eyes>)
class Teeth (Generic Collection)
-public CreateHead(XML <teeth>)
-public CreateHead(XML <nose>)
-public CreateHead(XML <chin>)
So we would receive the initial update which could be something like:
<eye id="1" state="open" />
<eye id="2" state="open" />
<tooth id="1" />
<tooth id="2" />
<tooth id="3" />
<tooth id="4" />
<tooth id="5" />
To build this we have a Factory object with a Factory method for Head when receives the XML.
Creating the Head object requires each of child (Ears, Eyes, Teeth, Nose, Chin) Factories to be called much the same way Head is created.
Then when something changes our application is alerted. So then we could do something like:
<eye id="1" state="shut" />
<eye id="2" state="shut" />
This creates a new Head object using the Head Factory which then calls the EyesFactory and returns an updated Head object.
I am wondering what is the best way to keep them in the know. We have the original Head and then incremental updates. We need to persist updates to the original Head object.
I know that I could do all of this pretty easly by manually processing them on each update, but looking for a pattern that addresses this.
Net Wreck, Sep 23, 2010