Navigation:  Programming Cookbook > Creating GUI Applications > Creating MVP Components >

Elemental MVP Components

Previous pageReturn to chapter overviewNext page

There are two types of MVP component that you'll come across; Elemental and Composite. It is worth considering these separately since they tend to be created and used in quite different ways.

In an elemental component, a single model connects to a single presenter and a single view. A triad such as this can be thought of as a basic component from which composite components can be built.

An example of an elemental component is TextPresenter. Here the default model is a ValueHolder wrapping a String and the default view (TextPresenter.Default view) is an instance of TextEdit.

Elemental components tend to be generic and not very application-specific. For this reason, you'll probably find that the existing set of elemental components will be sufficient for most purposes. Sometimes you may need to create additional elemental components that are specific to a particular sort of domain data but these are generally quite rare. One domain specific example, however, is the Scribble component which is part of the Scribble sample package.

Let's take a look at some examples of the objects that make up elemental MVP components in the basic Dolphin image:

Presenter class

Model class

View name

View class

Notes

TextPresenter

ValueModel

TextPresenter.Default view

TextEdit

The value model is expected to hold a String value. With the TextEdit view installed this is a single line text editing component.

TextPresenter

ValueModel

TextPresenter.Multiline text

MultilineTextEdit

Again the value model is expected to hold a String value. With it the MultilineTextEdit view installed this is a multi-line text editing component.

NumberPresenter

ValueModel

NumberPresenter.Default view

TextEdit

Here the value model is expected to hold a Number value.

ListPresenter

ListModel

ListPresenter.Default view

ListBox

The elements of the list model are displayed in a single column Windows listbox.

ListPresenter

ListModel

ListPresenter.Enhanced list view

ListView

The elements of the list model are displayed in a multicolumn Windows list view.

BooleanPresenter

ValueModel

BooleanPresenter.Default view

CheckBox

The value model is expected to hold a Boolean value.

Notice how all of the above components are fairly generic and are likely to be used in many different applications.