package mvp; import java.util.*; import java.io.*; /**** * * Class Model is an abstract parent class for model classes in an MVP design. * See * Fisher SE lecture notes for further discussion of the MVP design * methodology. * * @author Gene Fisher (gfisher@calpoly.edu) * @version cvs 1.12, 2003/02/02 * */ public abstract class Model extends Observable implements Serializable { /** * Construct a model with the given View. *
     * post: this'.view = view;
     *                                                                   
*/ public Model(View view) { this.view = view; } /** * Construct a model with no view. This constructor is typically used for * submodel objects that have no individual view of their own, but have a * subview that is part of a larger parent's view. *
     * post: this'.view = null;
     *                                                                   
*/ public Model() { view = null; } /** * Set the view of this to the given view, if the view is not already set. * This setView method is used if this must be constructed before its * companion view is constructed, and therefore the view will not be * available to pass to the constructor. *

* Models with multiple and/or dynamically changeable views must manage * view changes with additional data members. This' canonical view can be * set only once, with either the constructor or one call to setView. *

     * pre: this.view == null;
     *
     * post: this'.view == view;
     *                                                                   
*/ public void setView(View v) { if (this.view == null) this.view = v; } /** * Return the view of this. *
     * post: return == view;
     *                                                                   
*/ public View getView() { return view; } /** * Perform appropriate exit processing, which typically includes exiting * the application program of which this model is a component. This method * is called from a companion view when the view's window is closed, and * such closing means that the application should exit. See View.setExitOnClose for * more information. *
     * post: ;   // must be specialized in subclasses
     *                                                                  
*/ public void exit() {} /** * Dump the entire contents of this in String form. This method is * intended to be called during testing to produce an inspectable and * differencable version of this model's data. This dump method is distinct * from the Object.toString method in Java, since toString may be used for * other purposes than producing a complete data dump. *
     * post: ;   // must be specialized in subclasses
     *                                                                  
*/ public String dump() { return null; } /** The canonical view for this model. Models with multiple views can add * additional view data members as necessary. */ protected View view; }