Boost logo

Boost :

From: Jesse Jones (jejones_at_[hidden])
Date: 2000-11-30 19:04:25


>> The view/controller needs three things from the model: 1)
>> notfication of changes so that it can invalidate itself 2) access
>> to the data so that it can render something for the user to see
>> 3) mutators so that the user can change the model. Notification can
>> be handled nicely via callbacks. I can imagine using some some sort
>> of callback architecture to handle the other two but it's not a
>> natural solution and it really seems like overkill when most views
>> will never be reused in other contexts.
>
>Just to illustrate the setup:
>
>--Record.h:
>
>class Record {
> ...
>};
>
>--Model.h:
>
>#include "signal.h"
>#include "record.h"
>class Model {
>public:
> signal<void, Record> sendUpdateToViews;
> void receiveUpdateFromView(Record r) {
> change model to reflect r
> sendUpdateToViews(r);
> }
>};
>
>--View.h
>
>#include "signal.h"
>#include "record.h"
>class View {
>public:
> signal<void, Record> sendUpdateToModel;
> void receiveUpdateFromModel(Record r) {
> updatescreen with r
> };
>
> // This is called when the view is changed
> void viewIsChanged(Record r) {
> sendUpdateToModel(r);
> }
>}

This isn't quite enough. On most systems you also need to redraw the view
when the OS determines that the window needs to be re-painted. So, I guess
you need yet another callback that allows you to fetch the data from the
model.

In most cases I think decoupling views from the model like this is
overkill. However if you do have a use for this decoupling this does seem
like a good way to go about it.

  -- Jesse


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk