Re: MVC Pattern or antipattern?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Tue, 24 Oct 2006 13:54:58 GMT
"Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx> wrote in message
news:1161643137.322074.227760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a domain model which is a simulation. I want to display the
state of the simulation at any given time, basically animated.
Since the Swing threading model requires all GUI work to be done on the
EventDispatcher thread, and all other long-running work to be done on
some other thread, I have a delima.
It might take some time to render a single "frame" (snapshot of the
domain model), and its desirable that rending doesn't interfere too
much with the simulation (not a strict requirement). Similarly,
updating the domain could take some time, and is not in any way atomic.
I'm trying to decide one the best approach to this problem...
I can think of three approaches:
A: Atomize the simulation thread. Make the simulation "pause" when the
painting starts.
B: Inline the simulation thread. Make the "updateSimulation" occure in
the event dispatcher thread.
C: Create a seperate immutable model that is a snapshot of the
simulation at reasonable time boundries, and pass this to the rendering
code through the event dispatchers.
I think solution C is the best solution, but I think there would be a
lot of overhead, as every simulation "snapshot" might not be used, and
isn't necessarily cheap to create. I'm sure I could work around this,
but if there is a better approach, I'd like to know about it before I
continue.
How about C, but instead of the simulation creating a snapshot at
regular intervals, the View requests a snapshot, and the simulation will
respond to it at the next convenient point in time? I'm assuming the
simulation is running in a seperate thread from the whatever powers the
view. I'm also assuming that it's more important for the simulation to run
undisturb than it is to get nice smooth framerates for your animation.
If this solution isn't acceptable, you should probably mention what kind
of time scales you're talking about. The solution is obviously different if
your simulation's time boundries occur once every 2 hours, and rendering
takes 3 minutes, versus your simulation's time boundries occur every 50
milliseconds, and rendering takes 1 second.
Question part 2:
My model really would know how to represent itself in the view, so
might it be useful to have my business objects implement a paint()
method (or the equivelent).
Wouldn't this defeat the whole purpose of using MVC? The idea is to
isolate the view from the model so that you can very the view. If you know
you're never going to vary the view, there isn't much to gain from using
MVC.
- Oliver
.
- Follow-Ups:
- Re: MVC Pattern or antipattern?
- From: Daniel Pitts
- Re: MVC Pattern or antipattern?
- References:
- MVC Pattern or antipattern?
- From: Daniel Pitts
- MVC Pattern or antipattern?
- Prev by Date: Re: JOptionPane and the EDT
- Next by Date: Re: MVC Pattern or antipattern?
- Previous by thread: MVC Pattern or antipattern?
- Next by thread: Re: MVC Pattern or antipattern?
- Index(es):
Relevant Pages
|
|