You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jon Stevens <jo...@latchkey.com> on 2000/10/16 00:19:04 UTC

[LONG] The Pull vs. Push MVC Model

Hi all,

<READ THIS FIRST>
Sorry for the cross posting, but I think that this is important to bring up
the issue across a few lists. If you would like to discuss this, please
subscribe to and only respond to the Turbine mailing list. You can subscribe
by sending email to turbine-on@list.working-dogs.com.
</READ THIS FIRST>

This document is to explain a different type of philosophy for working with
Context based MVC tools like WebMacro (WM) and Velocity (V) than I think
that the Turbine community is used to. The requirement for this philosophy
has come up recently during Scarab development and I would like to share and
document it with you all. Many thanks to Brian B for being patient with me
and trying to explain exactly what he wants to see. So, let me start off by
giving a little bit of history and then moving on from there...

The current encouragement that Turbine gives to developers is to do a
mapping between one Screen (Java) and one Template (WM or V). The way it
works is that you build up a Context object that is essentially a Hashtable
that contains all of the data that is required to render a particular
template. Within the template, you refer to that data in order to format it
for display. I will refer to this as the "Push MVC Model." This IMHO is a
perfectly acceptable, easy to understand and implement approach.

We have solved the problem of being able to display the data on a template
without requiring the engineer to make modifications to the Java code.

However, it has a shortcoming in that it makes it more difficult to allow
the template designer (ie: a non programmer) the ability to move information
on a template from one template to another template because it would require
the logic in the Java code to be modified as well. For example, say you have
a set of "wizard" type screens and you want to change the order of execution
of those screens. In order to do so, you can't simply change the Next/Back
links you need to also change the Java code. This is bad because at least
for CollabNet, our clients will require us to provide that ability.

So, beginning with Scarab, I am going to try another model which I will
describe as the "Pull MVC Model". What this entails is the ability to create
an object that is able to "pull" the required information out at execution
time within the template. Thus, it becomes the job of the template designer
to understand the API of objects available to him/her to take advantage of.

Instead of the developer telling the designer what Context names to use for
each and every screen, there is instead a "global" set of objects available
for the template designer to pick and choose from. Gone are the days where
one would have a Java class that would be responsible for building the
context up for the template. Instead, there would be a single base class
that stuffs these objects into the context for every request and there is a
documented API that the template designer can refer to in order to access
the information that he/she needs to get at. Of course this information is
only retrieved when requested and can also be managed in a cache for reuse.

By moving to a "Pull" model, it becomes possible to more easily achieve
complete independence from the Java engineers in order to not only change
the look and feel (UI) of the site but also the information architecture
(IA) layout and flow of the site.

While this puts more requirements on the Java engineer to make sure that the
template designer has a well defined API, it will save the Java engineer
many hours further down the road when the client requests IA changes because
now the responsibility is on the template designer to make the changes.

I hope that this makes sense to everyone. I'm sure that some of you are
probably saying "well, duh!." However, this is really not the model that has
been encouraged so far within Turbine nor within other products such as XMLC
(which actually operates *only* on the Push model), so I believe that it is
somewhat uncharted territory for some people. The only products that I can
think of right now that encourage this is JSP taglibs and Tea, however, I
still feel as though they have missed the boat on this in one way or
another.

I'm going to start working on a framework that will make it easy to create a
container framework for these objects that will allow them to easily deal
with the multithreading issues as well as the caching issues involved with
these objects. I suspect that I will be able to rely on Turbine's Services
model as well as Turbine's Global cache model for the basis of most of this
code. 

Comments are appreciated.

thanks,

-jon

-- 
http://scarab.tigris.org/    | http://noodle.tigris.org/
http://java.apache.org/      | http://java.apache.org/turbine/
http://www.working-dogs.com/ | http://jakarta.apache.org/velocity/
http://www.collab.net/       | http://www.sourcexchange.com/


Re: [LONG] The Pull vs. Push MVC Model

Posted by Christoph Reck <Ch...@dlr.de>.
Sorry, the previous mail should have gone to the Turbine
list. The post there had a ReplyTo: velocity-user@jakarta.apache.org

:( Christoph

Re: [LONG] The Pull vs. Push MVC Model

Posted by Christoph Reck <Ch...@dlr.de>.
The configurable PULL MVC is the way to go IMHO!

Daves approach with the TemplateTag and the XML configuration
seems to be a good idea. But for a simplest PULL implementation
its initially an overkill.

My 2c: currently I'm experimenting in using Velocity as the
configuration language - instead of writing XML and the parsing
application! The approach seems simple and is yielding fruits!

Extension is done via templates/control and mainly reusing 
predefined java classes (e.g. url/script calls, file loads, dir 
list access). Additional classes may be placed in the webapp and 
be accessed either as static functions, singletons, or as beans.

Velocity can place parameters into the context via the #set 
directive to be used by the PULL MVC pattern. By adding some tools 
to the control context allows instantiating/calling any java class 
and placing the resulting objects into the screen context. 

I'm using a templates/control path and a VelocitySiteControl class 
(a VelocitySiteScreen extension) that loads a control template that 
defines the context for the screen/navigation/layout. It essentially 
maps actions to the template/control pages and provides a default 
control action for every screen.

The VelocitySiteControl also loads a set of constants at startup 
(from a *.vm file!) defining constants and context objects for
every screen. It also could load a defaults.vm file before the 
control template is loaded/run (could be done also by a #parse
within the control template itself).

I'm also thinking in using a $param stack to pass in and out values
to views (essentially reusable velocity screen fragments) to be used
as a HVMC pattern. This will avoid poluting the main screen context 
with variables.


The above stated adds the long-missing control branch to the
Turbine Model2+1 paradigma, making it a real HMVC. Maybe a 
module/control could be added to tubine with the VelocitySiteControl!


I'll post more when I have the pattern running.

Any interest, ideas, comments - specifically in using velocity as
the controller scripting language setting up the Pull MVC context?

:) Christoph