![]() ![]()
Last edited - March / 99 |
-- Hear and forget; see and remember; do and understand...
the model-view-controller (MVC) design pattern
the heartbeat view
The views in this app are very simple. The basic
view (source - again,
most of the AWT related code was created with Visual Cafe) has a
constructor that takes a model and registers for updates
from it. The
The applet (source) is a
view as well. Its Implementation NoteIn the applet case, there was some data sent that wasn't used (the heartbeat number was ignored), which some could consider wasteful. In fact, if the model provided an accessor method for the view to use for obtaining the current heart beat, then there would be no need for the current heart beat to be sent as data in the model'snotifyObservers method. Instead, a null value could be sent during
the update. Then, if a view needed the
current heart beat, it could access it directly from the
model, which is always passed to the
update method.
But this model doesn't have any accessors like that. It could - and it's easy to argue that having views get their data directly from the model is a better design:
It really depends on how complicated your application is going to be and whether or not you want to distribute it. Personally, I prefer the data update object approach. I'm not too concerned with efficiency right now - machines and JVM implementations will get faster and I'm satisfied with letting those engineers/developers concentrate on improving my run-time performance. Distributing my applications also helps trim my run-times as well and the data update object approach lends itself nicely to being distributed. But I tend to use the data update object method mainly because it helps me focus on what information about the model is important. I'm forced to do that when designing the data update objects. Again, it's the design process that MVC has helped tune for me. I'm asking better questions about the objects in my application, their functions, and what information they should have access to and provide. Since I find it is still an evolving process in my own head, it is probably something you probably should play around with too, in order to find out what you like and don't like. I've even got some suggestions on how to play around... |