MVC/MVP modeling many to one

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

MVC/MVP modeling many to one

Costas Menico
After reading about MVC/MVP my  understanding is that you can have a
model with many view/controllers wired to it. (The simple concept)

Models send #changed messages and dependent views receive them as
#update and then request model data for subsequent display.

Now the problem. I have one view but have many models (actually they
are the same model class, but many instances). I will be displaying
changes in the models as they happen in a scrollable listbox control.

What is the correct methodology for this? I am assuming the simple
way would be for the one view to register with each model instance its
dependency. But Dolphin MVP there is only one model: per VP pair.  

So how is this handled?

Thanks

Costas


Reply | Threaded
Open this post in threaded view
|

Re: MVC/MVP modeling many to one

Bill Schwab-2
Costas,

> After reading about MVC/MVP my  understanding is that you can have a
> model with many view/controllers wired to it. (The simple concept)
>
> Models send #changed messages and dependent views receive them as
> #update and then request model data for subsequent display.
>
> Now the problem. I have one view but have many models (actually they
> are the same model class, but many instances). I will be displaying
> changes in the models as they happen in a scrollable listbox control.

You can probably think about this as multiple items in a ListModel that
becomes the model to a ListPresenter.  The biggest problem you'll have is
updating the appearance of the list, and that can be done via a ListModel (I
think) method that's something like #updateItemAtIndex:(????).  One way to
do it would be to register interest in events triggered by or about the
items such that they are sent to the parent presenter, and have it lookup
the index and do the updates.  If you have many such list presenters, you
might consider subclassing ListPresenter to add the lookup/update
functionality.  Perhaps somebody has a more elegant suggestion.

Beware problems in Windows' handling of control notifications.  You _might
find that you'll need to use #queueDeferredAction: to make the actual
updates.  A search of Ian's archives should turn up the conditions under
which this can be an issue.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: MVC/MVP modeling many to one

Ted Bracht-2
In reply to this post by Costas Menico
Hi Costas,

[hidden email] (Costas Menico) wrote in message news:<[hidden email]>...

> After reading about MVC/MVP my  understanding is that you can have a
> model with many view/controllers wired to it. (The simple concept)
>
> Models send #changed messages and dependent views receive them as
> #update and then request model data for subsequent display.
>
> Now the problem. I have one view but have many models (actually they
> are the same model class, but many instances). I will be displaying
> changes in the models as they happen in a scrollable listbox control.
>
> What is the correct methodology for this? I am assuming the simple
> way would be for the one view to register with each model instance its
> dependency. But Dolphin MVP there is only one model: per VP pair.  
>
> So how is this handled?

I would create a separate class with a collection instance variable
(typically a ListModel). Collect the instances of your model in that
ListModel and connect the 'holder' class to the VP pair.

>
> Thanks
>
> Costas

Ted