Navigation:  Programming Cookbook > Creating GUI Applications > Pluggability >

Pluggable Views

Previous pageReturn to chapter overviewNext page

With MVP, all of the elements are pluggable. If you wish to change the visible representation of a component then you merely plug a different sort of view onto the presenter. For example, you might choose to plug a "Multiline text" view onto a TextPresenter to replace in the single line "Default view".

Try the following examples:

TextPresenter show.


This will create a TextPresenter component connect it to a TextEdit view (the default). By evaluating the above example, the view is automatically cradled by a top-level shell window for convenience but we can ignore this detail here and just focus on the text editing. As you type, you'll notice that you can't enter any newline characters in the edit field since a TextEdit turns out to be a Windows control that only supports single line text.

However, it is also possible to open other views onto a TextPresenter.

TextPresenter show: 'Multiline text'.


As you might imagine, you are now able to enter text into this presenter over multiple lines. The important point here is that the same class, TextPresenter is handling the input to the model in both cases. However, the way the information is displayed, on one or over multiple lines, is determined by the type of view plugged onto it.

Another experiment, this time using a BooleanPresenter, might be:

BooleanPresenter show.

BooleanPresenter show: 'Push to toggle'.