becker.util
Interface IModel

All Known Subinterfaces:
INameSurferModel
All Known Implementing Classes:
AbstractModel, SampleNameSurferModel, ViewList

public interface IModel

Classes implementing IModel have a standard protocol for adding views (such as a graphical user interfaces).

A program with a graphical user interface is typically composed of a model and one or more views. The model provides an abstraction of the problem to be solved while a views shows a particular representation (often graphical) of the model. Often there are several different views of the model. When the model changes, all of the views should be notified so they can update the information they display.

At least one of the classes modeling the problem should implement the IModel interface to provide a standard protocol for adding or removing a view.

The minimal class implementing IModel is:

   class MyModel extends Object implements IModel
   {
      private ArrayList views = new ArrayList();
      
      public MyModel()
      {   super();
      }
     
     public void addView(IView aView)
     {   this.views.add(aView);
     }
     
     public void removeView(IView aView)
     {   this.views.remove(aView);
     }
     
     public void updateAllViews()
     {  for(IView v : this.views)
        {  v.updateView();
        }
     }
  }   
  

The combination of IModel and IView is a simplification of the classic Observer pattern. IObservable, IObserver and Observers may be used to implement that pattern without simplification.

Classes may also extend AbstractModel, which provides an implementation of this interface.

Author:
Byron Weber Becker
See Also:
IView, AbstractModel

Method Summary
 void addView(IView aView)
          Add a view to a list of views.
 void removeView(IView aView)
          Remove a specific view from the list of views.
 void updateAllViews()
          Update all the views that have been added to this model.
 

Method Detail

addView

void addView(IView aView)
Add a view to a list of views. Each view is notified each time an event occurs that changes the state of the model.

Parameters:
aView - The view to add.

removeView

void removeView(IView aView)
Remove a specific view from the list of views.

Parameters:
aView - The view to remove.

updateAllViews

void updateAllViews()
Update all the views that have been added to this model.