Design pattern for multiple views

Discussion in 'Java' started by Ruben, Mar 27, 2006.

  1. Ruben

    Ruben Guest

    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!
    Ruben, Mar 27, 2006
    #1
    1. Advertising

  2. Ruben

    Chris Uppal Guest

    Ruben wrote:

    > 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
    Chris Uppal, Mar 27, 2006
    #2
    1. Advertising

  3. Ruben

    Oliver Wong Guest

    "Ruben" <> wrote in message
    news:...
    > 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
    Oliver Wong, Mar 27, 2006
    #3
  4. > 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.

    --
    Need to get from a Foo object to a Bar object in Java?
    Ask Prospector: http://snobol.cs.berkeley.edu
    Want to play tabletop RPGs over the internet?
    Check out Koboldsoft RPZen: http://www.koboldsoft.com
    Dave Mandelin, Mar 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sims
    Replies:
    1
    Views:
    389
    Kim André Akerø
    May 6, 2004
  2. sunny
    Replies:
    1
    Views:
    439
    Salt_Peter
    Dec 7, 2006
  3. Pallav singh
    Replies:
    0
    Views:
    338
    Pallav singh
    Jan 22, 2012
  4. Pallav singh
    Replies:
    0
    Views:
    384
    Pallav singh
    Jan 22, 2012
  5. Pallav singh
    Replies:
    1
    Views:
    439
    Peter Remmers
    Jan 22, 2012
Loading...

Share This Page