class design - clarification

S

Spitfire

Whenever I parse an XML file, using a DOM parser, I get a DOM object
which I can use to access whichever element I want to extract. However,
I cannot mutate any of them in place, preserving therefore the
consistency of the values in the object. How do I design such a class if
I have to for another similar purpose?

Imagine a scenario in which I construct my own XML/HTML parser. So my
parser takes a URL or a file and then constructs a DOM object which
represents the entire parsed doc. How do I design this DOM object class?
I want to have variables which the other classes can only see, but not
modify! I want to have methods which the other class can invoke, like
'getElementsByName' ... etc. I'm stuck in finalizing the design of the
class. This is just for academic purposes and therefore lets keep
advices against 'reinventing the wheel' away for a while.
 
C

Chris Smith

Spitfire said:
Imagine a scenario in which I construct my own XML/HTML parser. So my
parser takes a URL or a file and then constructs a DOM object which
represents the entire parsed doc. How do I design this DOM object class?
I want to have variables which the other classes can only see, but not
modify! I want to have methods which the other class can invoke, like
'getElementsByName' ... etc. I'm stuck in finalizing the design of the
class. This is just for academic purposes and therefore lets keep
advices against 'reinventing the wheel' away for a while.

Once smart way to proceed might be to implement wrapper classes for all
the standard DOM interfaces. These wrappers would throw exceptions if
the caller tries to modify the document; but would pass through the
function calls that just read from the document. They would also
construct wrappers on the fly for any other interfaces retrieved from
them.

This is the same thing that happens, for example, with Java's standard
Collections.unmodifiableList and other such functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top