Sharkysoft home

lava.mv
Class MvModel

java.lang.Object
  |
  +--lava.mv.MvModel
Direct Known Subclasses:
MvModelExtra, SpeedometerModel

public abstract class MvModel
extends java.lang.Object

Abstract base class for models.

Details: MvModel should be used as the base class for objects representing models in programs that implement model-view separation.

Since:
1998.10.22
Version:
2000.02.23
See Also:
IMvView

Constructor Summary
protected MvModel()
           
protected MvModel(java.lang.Object id)
          Specifies model id.
 
Method Summary
protected  IMvEventDispatcher getEventDispatcher()
           
protected  void notifyViews(int type, java.lang.Object[] params)
          Sends MvModelEvent message.
protected  void notifyViews(java.lang.Object message)
          Notifies all registered views of a change in the model.
 void registerView(IMvView view)
          Registers a IMvView with this MvModel.
protected  void setEventDispatcher(IMvEventDispatcher dispatcher)
           
 void unregisterView(IMvView view)
          Unregisters a IMvView with this MvModel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MvModel

protected MvModel(java.lang.Object id)
Specifies model id.

Details: This constructor allows the caller to specify the object that is used to identify the model in calls to views' updateView method.

Parameters:
id - the model id

MvModel

protected MvModel()
Method Detail

setEventDispatcher

protected void setEventDispatcher(IMvEventDispatcher dispatcher)

getEventDispatcher

protected IMvEventDispatcher getEventDispatcher()

notifyViews

protected void notifyViews(java.lang.Object message)
Notifies all registered views of a change in the model.

Details: notifyViews calls the updateView method of all IMvViews registered with this MvModel, sending each IMvView the indicated message. This message should be an Object that each IMvView expects to receive.

Usually, you will want to make a special message class for this purpose. Ideally, each message contains "delta information" (i.e., model change information) that each view can use to determine an appropriate and efficient view update strategy.

If a view throws an Exception while being notified, notifyViews catches it and dumps the stack trace using the Exception's printStackTrace method.

Parameters:
message - the update message
Since:
1998.10.22

notifyViews

protected void notifyViews(int type,
                           java.lang.Object[] params)
Sends MvModelEvent message.

Details: notifyViews is a helper method designed to make message dispatching easier. notifyViews first creates a new MvModelEvent object based on the supplied parameters (type, params), and then it dispatches it using the original notifyViews method.

Parameters:
type - the message type ID
params - the message parameter list
Since:
2000.02.23

registerView

public void registerView(IMvView view)
Registers a IMvView with this MvModel.

Details: registerView registers the given IMvView to receive update messsages from this MvModel when it changes. The IMvView should expect to receive messages from this MvModel and know how to handle them.

IMvViews that register with this MvModel should unregister themselves when the views are no longer used. See unregisterView.

Parameters:
view - the IMvView to register
Since:
1998.10.22

unregisterView

public void unregisterView(IMvView view)
Unregisters a IMvView with this MvModel.

Details: unregisterView removes the given IMvView from the this MvModel's list of registered views. The IMvView will no long receive update messages from this MvModel.

IMvViews should unregister themselves when they are no longer in use.

Parameters:
view - the IMvView to unregister
Since:
1998.10.22

Sharkysoft home