|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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 ArrayListviews = 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.
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 |
---|
void addView(IView aView)
aView
- The view to add.void removeView(IView aView)
aView
- The view to remove.void updateAllViews()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |