Design pattern for multiple views

R

Ruben

Hi all,

I'm working on a simple presentation-program. I've chosen for a Model
View Controller architecture. The model contains the (static) elements
of the presentation (such as text, images, etc) and the (dynamic)
transitions between presentation states (such as highlight an element,
continue to next slide, etc). The static and dynamic part are the
essence of a presentation, and is included in the "Model" part of the
MVC.

The view-component of the MVC is responsible for painting the
presentation to screen. For the static part of the presentation, the
view uses some kind of LayoutManager. The dynamic part uses something
like a TransitionManager, which maps each transition to an animation.
In the future, I intend to support multiple views (2d, 3d, etc.). Every
possible transition is supported by each view. Moreover, each view can
have multiple kinds of animations to visualize an action. In other
words, the LayoutManager and TransitionManager are view-dependent.

Example:
The presentation-action "next-slide" is supported by the 2D view, which
provides three different animations: no-animation, checkerboard, slide
(or whatever). It is also supported by the 3D view which uses entirely
different animations. The presentation action "highlight-bullet" is
also supported by the 2D and 3D view, again using entirely different
animations.

Based on these requirements, I have 2 questions:
1. Users think of presentations as the combination of the static,
dynamic (actions), and layout components, but layout is view-dependent.
Where do I put information about the layout of my presentation? Do I
include layout information for each possible view in the Presentation
object, or somewhere else?
2. What kind of OO-Design best supports the view-independent creation
of Layout and Animations? I'm thinking of some kind of AbstractFactory
which is capable of listing all Animations supported by a particular
view for a particular PresentationAction, and subsequently creating
them. I'm not sure if this is the best solution.

Maybe someone has the answers to these two questions, has some hints,
or has come across similar problems. Any help is much appreciated!
 
C

Chris Uppal

Ruben said:
I'm working on a simple presentation-program. I've chosen for a Model
View Controller architecture.

The point about MCV (or similar) is that it's a good idea to separate
presentation logic from the domain logic (the model). But that gets a little
awkward when the domain /is/ presentation!

So I think you should expect to have to deviate from classic MVC in various
ways. I think you have two options (there may be more, but I can't think of
'em).

One is to give up on pure MVC, and just accept that your "model" is both
domain, /and/ presentation. So the model has responsibility for managing its
own display elements.

The other is to conceive of the model as a logical /specification/ of the
display, and for the presentation logic to consist of one or more views that
can /implement/ that specification. So the model doesn't contain layout as
such, but it does contain information that any given view can use to configure
a suitable LayoutManager. Similarly for transitions, etc.

Which of these, if either, works best depends on how closely you have to, or
want to, structure your application around the way that the users think of it.
A different way to think about the choice, is do you want to expose your
model/presentation distinction to the users ? Does you application say "this
is how a checkerboard transition looks if you are using 2D, this is how the
'same' transition looks using 3D", and so on ?

-- chris
 
O

Oliver Wong

Ruben said:
I'm working on a simple presentation-program. I've chosen for a Model
View Controller architecture. The model contains the (static) elements
of the presentation (such as text, images, etc) and the (dynamic)
transitions between presentation states (such as highlight an element,
continue to next slide, etc). The static and dynamic part are the
essence of a presentation, and is included in the "Model" part of the
MVC.

I'd store the fact that there IS a specific transition (e.g. fadein,
checkerboard, whatever) between slides 3 and 4 in the model, but I'd store
the actual "state" of those transitions (e.g. 500ms has elapses in the
rendering of the transition animation) in the view, not the model.
The view-component of the MVC is responsible for painting the
presentation to screen. For the static part of the presentation, the
view uses some kind of LayoutManager. The dynamic part uses something
like a TransitionManager, which maps each transition to an animation.
In the future, I intend to support multiple views (2d, 3d, etc.). Every
possible transition is supported by each view. Moreover, each view can
have multiple kinds of animations to visualize an action. In other
words, the LayoutManager and TransitionManager are view-dependent.

Example:
The presentation-action "next-slide" is supported by the 2D view, which
provides three different animations: no-animation, checkerboard, slide
(or whatever). It is also supported by the 3D view which uses entirely
different animations. The presentation action "highlight-bullet" is
also supported by the 2D and 3D view, again using entirely different
animations.

What's unclear is how which animation is decided. If there's a
"checkerboard transition" in the 2D view, but not in the 3D view, then you
can't actually say in the model "Please do a checkerboard transition here".
If all you say in the model is "please do a transition here", then how do
you know which one to do? Checkerboard? slide? Something else?
Based on these requirements, I have 2 questions:
1. Users think of presentations as the combination of the static,
dynamic (actions), and layout components, but layout is view-dependent.
Where do I put information about the layout of my presentation? Do I
include layout information for each possible view in the Presentation
object, or somewhere else?

I'm not sure what you mean by layout. Are you saying that the model
might, for example, contain strings of text, and it's up to the view to
determine handle word-wrapping? Usually, with presentations, you want
WYSIWYG, so I'd imagine the layout is "hard-coded" into the model.
2. What kind of OO-Design best supports the view-independent creation
of Layout and Animations? I'm thinking of some kind of AbstractFactory
which is capable of listing all Animations supported by a particular
view for a particular PresentationAction, and subsequently creating
them. I'm not sure if this is the best solution.

Me neither until you clarify the above.

- Oliver
 
D

Dave Mandelin

The other is to conceive of the model as a logical /specification/ of the
display, and for the presentation logic to consist of one or more views that
can /implement/ that specification. So the model doesn't contain layout as
such, but it does contain information that any given view can use to configure
a suitable LayoutManager. Similarly for transitions, etc.

This is the way to go. I once used this idea to produce reports that
could be viewed as HTML, PDF, and TSV (for Excel), and it worked very
well. The 'model' was a table-like description of the layout, and it
was rendered appropriately in each format. Some formats supported
features that were omitted in others (e.g., no lines in TSV). There are
at least 2 good OO designs for this:

1. The model is essentially a 'specification' describing a presentation
expressed in some 'language', and each view is an 'interpreter' for
that language. The views can end up looking kind of like visitors.

2. Create only one 'abstract' interpreter. This interpreter calls
abstract methods to implement the actual display operations. Each view
is a set of implementations of the abstract methods.

1 is more flexible; 2 is more conducive to code sharing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top