Article Preview
Buy Now
| Print: | |
| PDF: |
Object-Oriented Thinking
Extending XMLReader
Applying the Chain of Responsibility Pattern
Issue: 4.3 (January/February 2006)
Author: Charles Yeomans
Article Description: No description available.
Article Length (in bytes): 7,271
Starting Page Number: 31
RBD Number: 4314
Resource File(s): None
Related Web Link(s):
http://www.declareSub.com/
Known Limitations: None
Excerpt of article text...
I needed to write some code to import databases in XML format into a database. Since such files tend toward the large, using an XMLReader object was the obvious choice. In the course of doing so, I quickly encountered a problem -- my event handlers were becoming massive Select Case statements that branched on an accumulation of variables holding table and field names.
<?xml version="1.0"?>
<Database>
<Table name="Customers">
<Record>
<Field name="Name">
<Data>
</Data>
</Field>
</Record>
</Table>
<Table name="Vendors">
<Record>
<Field name="Name">
<Data>
</Data>
</Field>
</Record>
</Table>
</Database>
This is just the sort of code that quickly becomes hard to maintain. I prefer to spend my efforts finding a better design. Here is my attempt at it.
We start with a subclass XMLReaderPlus of XMLReader. To it we add a public property Handler as XMLReaderHandler. XMLReaderHandler is to be a class interface for handling XMLReader events. For each XMLReader event, we add a corresponding method to XMLReaderHandler having the same parameters and return type. Thus XMLReaderHandler has methods like these:
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.
|








