Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MVC question

 
Iven Breeze
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic