6

What is the difference between the push & pull models of MVC?

Is Struts2, Spring MVC Pull based?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Punit Patel
  • 901
  • 1
  • 12
  • 25

4 Answers4

8

According to Struts2 Interview Questions and Answers

Struts2 is a Pull-MVC based architecture, in which all data is stored in Value Stack and retrieved by view layer for rendering.

Specifically:

In case of Push-MVC the data (Model) is constructed and given to the view layer by the Controllers by putting it in the scoped variables like request or session. Typical example is Spring MVC and Struts1. Pull-MVC on the other hand puts the model data typically constructed in Controllers are kept in a common place i.e. in actions, which then gets rendered by view layer.

Giacomo Alzetta
  • 2,431
  • 6
  • 17
Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115
3

The concept of push and pull refers to what the server does in relation to the client. In a "push" application, a server is pushing or sending data to clients at it's own initiation. In a "pull" application, the server is pulling or waiting for and receiving messages initiated by clients.

A good explanation is given here mvc-pattern-its-importance-push-pull and here pull-vs-push-mvc-architecture

Struts1 and Spring both use Push MVC. This question might be helpful spring-mvc-complex-model-population-from-multiple-sources Struts2 uses Pull

Community
  • 1
  • 1
Tala
  • 8,888
  • 5
  • 34
  • 38
  • 2
    Sorry but the whole world wide web is saying the opposite. Spring MVC is PUSH, Struts1 is PUSH, but **Struts2 is PULL**... – Andrea Ligios Jul 03 '13 at 08:12
  • But which is better between MVC Push and Pull – Punit Patel Jul 03 '13 at 10:13
  • It really depends on what you're building. If one was better in every case, we wouldn't use another. Read through the articles above and try to decide what bettter suits you. If you still have questions - ask another question with more concrete requirements for your system – Tala Jul 03 '13 at 10:22
2

Struts2, Play! and so on are all kinds of pull model implementations of the MVC pattern.

Terms "push" and "pull" refer directly to the type of implementation of the observer pattern used between View and Model. As stated in GoF Observer pattern explaination, we have:

At one extreme, which we call the push model, the subject sends observers detailed information about the change, whether they want it or not. At the other extreme is the pull model; the subject sends nothing but the most minimal notification, and observers ask for details explicitly thereafter.

This means that the implementation of push model requires that View and Model are implemented using the same language and they are executed in the the same environment. Good examples of this kind of implementation are Javascript single page applications, in which View and Model components execute inside the browser and a framework, i.e. Backbone, provides MVC (a.k.a. Observer) mechanism. Often, Model component interacts with some kind of server API, to persist and get persisted datas.

On the other hand, pull model lets you implement MVC using different technologies for View component, and Controller / Model components. In this kind of MVC, there is not an explicit use of the Observer pattern and View interacts exclusively with Controller. View component, which usually executes into the browser, sends to Controller component request of model's updates or model's state. Usually requestes are implemented using HTTP protocol. This kind of implementation requires the use of some type of "augmented HTML scripting language", such as JSP, which allows to create automatically the link between View and Controller.

riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
  • Spring MVC isn't pull model. – Aleksandr M Mar 02 '15 at 10:14
  • @AleksandrM, it seems you're right. I have found many resources that say that Spring is an implementation of push model. I have always believed that Spring MVC implements pull model. In the push model, the View observes the model, but how the hell is this possible using JSPs?! Anyway, I have correct my answer. – riccardo.cardin Mar 02 '15 at 13:31
  • @AleksandrM Ok, I've got it. Your definition follows what is said in this discussion [J2EE patterns: Clarification on MVC Pull and MVC Push](http://www.theserverside.com/discussions/thread.tss?thread_id=22143). I will update asap my answer accordingly to it :) – riccardo.cardin Mar 02 '15 at 16:28
-1

Sorry .. I dont think that struts 1, struts 2 and spring MVC can be taken as PUSH MVC ..

as both of all frameworks use a front controller[Filer class for Struts , And Controller Listener for Spring ] defined in their respective deployment descriptor. Now both of all these frame work save the form data in their respective bean[Or model] object using that controller by reflection.

Now from our Action Controller we can receive the bean object and will get the values but in the front controller where the bean object[or model] is actually generated set the value in their resperctive field by using request.getParameter(param) or request.getParameterValues(param) methods internally.. So this can be considered as PULL.

So as per my thinking we can say that These framework can use two layers namely PULL layers used by end programmer and PUSH layers used by framework base classes.