package mvp;

import java.util.*;
import java.io.*;

/****
 *
 * Class Model is an abstract parent class for model classes in an MVP design.
 * See <a href = "http://www.csc.calpoly.edu/~gfisher/classes/309/lectures">
 * Fisher SE lecture notes </a> 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.
     *                                                                    <pre>
     * post: this'.view = view;
     *                                                                   </pre>
     */
    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.
     *                                                                    <pre>
     * post: this'.view = null;
     *                                                                   </pre>
     */
    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.
     *                                                                      <p>
     * 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>
     * pre: this.view == null;
     *
     * post: this'.view == view;
     *                                                                   </pre>
     */
    public void setView(View v) {
        if (this.view == null)
            this.view = v;
    }

    /**
     * Return the view of this.
     *                                                                    <pre>
     * post: return == view;
     *                                                                   </pre>
     */
    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 <a href=
     * View.html#setExitOnClose(boolean)> <tt>View.setExitOnClose</tt> </a> for
     * more information.
     *                                                                   <pre>
     * post: ;   // must be specialized in subclasses
     *                                                                  </pre>
     */
    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.
     *                                                                   <pre>
     * post: ;   // must be specialized in subclasses
     *                                                                  </pre>
     */
    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;

}