Navigation:  Programming Cookbook > Creating GUI Applications > Pluggability >

Pluggable Models

Previous pageReturn to chapter overviewNext page

If you wish to change the way the data is held by a component then the model itself can be replaced by another. For example, a ListPresenter creates, and connects itself to, a ListModel by default. If you take a look at the ListModel class you'll see that it is basically a wrapper around any sequenceable collection.

Note, the default model for any presenter is specified in its #defaultModel class method. You'll see that ListPresenter class>>defaultModel answers a ListModel created to wrap an OrderedCollection.

Here's another example:

Create a standard ListPresenter and fill it:

lp:= ListPresenter show.

lp model addAll: Object methodDictionary keys.


However, it is also possible to create a ListPresenter on a model different from the default:

lp:= ListPresenter showOn: (ListModel with: SortedCollection new).

lp model addAll: Object methodDictionary keys.


This time all the method selectors in the list appear in sorted order by warrant of the SortedCollection model we gave to the presenter when it was created.