Back to list
Views:   4.7K
Replies:  0

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.

class Head
-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>);
  return h;
class Ears (Generic Collection)
class EarsFactory
-public CreateHead(XML <ears>)
class Eyes (Generic Collection)
class EyesFactory
-public CreateHead(XML <eyes>)
class Teeth (Generic Collection)
class TeethFactory
-public CreateHead(XML <teeth>)
class Nose
class NoseFactory
-public CreateHead(XML <nose>)
class Chin
class ChinFactory
-public CreateHead(XML <chin>)

So we would receive the initial update which could be something like:

<head state="full">
  <ear id="1">
  <ear id="2">
  <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:

<head state="partial">
  <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
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.