Talk:Builder

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
Line 3: Line 3:
 
--
 
--
  
Thought I might share a link to this "[[http://www.neocoders.com:8080/neocoders/projects/vgl/design-documentation/package-vgldocument-utils|"Stateful Builder"]], where a SAX parser drives a Builder that builds a Composite. The Builder implements the State pattern, and is in a particular state for each XML element that it is currently parsing.  
+
Thought I might share a link to this [[http://www.neocoders.com:8080/neocoders/projects/vgl/design-documentation/package-vgldocument-utils |"Stateful Builder"]], where a SAX parser drives a Builder that builds a Composite. The Builder implements the State pattern, and is in a particular state for each XML element that it is currently parsing.  
  
 
Incidentally, for a lot less code, you can also use use a kind of Interpretor pattern to parse an XML file into a Composite; where the Composite is also an Interpretor. You make yourself a SAXParser, then when you get a "startElement" event from it (for the root XML element) you instantiate the root Composite element, passing the parser to the element's constructor. The root Composite element attaches itself as a listener to the parser. For each "startElement" event the root gets, it creates the appropriate child, to which it passes the parser. The children in turn listen to the parser and make appropriate children for each "startElement" event that they hear. Of course, this lumps the loading function into the Composite, which is a little quick-and-dirty.
 
Incidentally, for a lot less code, you can also use use a kind of Interpretor pattern to parse an XML file into a Composite; where the Composite is also an Interpretor. You make yourself a SAXParser, then when you get a "startElement" event from it (for the root XML element) you instantiate the root Composite element, passing the parser to the element's constructor. The root Composite element attaches itself as a listener to the parser. For each "startElement" event the root gets, it creates the appropriate child, to which it passes the parser. The children in turn listen to the parser and make appropriate children for each "startElement" event that they hear. Of course, this lumps the loading function into the Composite, which is a little quick-and-dirty.

Revision as of 02:27, 7 October 2008

Created the page --Elliot Fisher 23:50, 6 October 2008 (UTC)

--

Thought I might share a link to this [|"Stateful Builder"], where a SAX parser drives a Builder that builds a Composite. The Builder implements the State pattern, and is in a particular state for each XML element that it is currently parsing.

Incidentally, for a lot less code, you can also use use a kind of Interpretor pattern to parse an XML file into a Composite; where the Composite is also an Interpretor. You make yourself a SAXParser, then when you get a "startElement" event from it (for the root XML element) you instantiate the root Composite element, passing the parser to the element's constructor. The root Composite element attaches itself as a listener to the parser. For each "startElement" event the root gets, it creates the appropriate child, to which it passes the parser. The children in turn listen to the parser and make appropriate children for each "startElement" event that they hear. Of course, this lumps the loading function into the Composite, which is a little quick-and-dirty.

You can also pass a DOM down into the construction of a Composite in the same way.

Lindsay Kay

Personal tools