This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes MVC question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "MVC question" Watch "MVC question" New topic
Author

MVC question

Iven Breeze
Greenhorn

Joined: Jan 11, 2004
Posts: 6
Is there an existing Model class that I should extend when I'm building the Model portion of an MVC app for the xml data?
I'm using JAXB to to marshal and unmarshal the xml data. That'll be in the Controller portion. I don't know if I should just create a brand new Model class to hold all the xml fields, or if I should extend an existing one.
[ January 11, 2004: Message edited by: Iven Breeze ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
Consider leaving your XML data as a DOM and creating a class/classes to give efficient access to it. Advantages:
1. avoids "brittle" code. - ie it won't break if you add some new attributes or elements to the XML as long as the basic structure does not change.
2. allows "lazy" initialization - if you wait until data is needed, you don't have to create a bunch of Java objects that may never be used.
I am working on an exam servlet application (about the 4th re-do of the architecture - one every 2 years ) in the first 3 I created data objects for each question. Now I take the DOM for the entire question set (possibly 500 questions) and locate all the question Elements when it is read in, but thats all. When question data is needed, the lookup for the n't question Element is very fast - it gets passed to a temporary "model" object that "knows how" to get the data out of the Element as needed for display.
With this architecture, adding new question types doesn't break anything.
Bill
 
GeeCON Prague 2014
 
subject: MVC question