class design - clarification

Discussion in 'Java' started by Spitfire, Feb 16, 2007.

  1. Spitfire

    Spitfire Guest

    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.

    --
    _ _ _]{5pitph!r3}[_ _ _
    __________________________________________________
    “I'm smart enough to know that I'm dumb.â€
    - Richard P Feynman
    Spitfire, Feb 16, 2007
    #1
    1. Advertising

  2. Spitfire

    Chris Smith Guest

    Spitfire <> wrote:
    > 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.

    --
    Chris Smith
    Chris Smith, Feb 16, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Wu
    Replies:
    2
    Views:
    409
    Paul Wu
    May 5, 2005
  2. E11
    Replies:
    1
    Views:
    4,711
    Thomas Weidenfeller
    Oct 12, 2005
  3. Karthik Kumar
    Replies:
    2
    Views:
    3,966
    Howard
    Sep 15, 2004
  4. John_Woo

    class design vs. db design

    John_Woo, Dec 19, 2006, in forum: Java
    Replies:
    2
    Views:
    318
    John_Woo
    Dec 19, 2006
  5. Fiaz Idris

    Character class [\W_] clarification

    Fiaz Idris, Dec 10, 2003, in forum: Perl Misc
    Replies:
    7
    Views:
    1,050
    William Herrera
    Dec 11, 2003
Loading...

Share This Page