Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push vs Pull Model in MVC

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

Is Struts2, Spring MVC Pull based?

like image 415
Punit Patel Avatar asked Jul 03 '13 07:07

Punit Patel


3 Answers

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.

like image 70
Ruchira Gayan Ranaweera Avatar answered Sep 21 '22 10:09

Ruchira Gayan Ranaweera


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

like image 26
Tala Avatar answered Sep 22 '22 10:09

Tala


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.

like image 33
riccardo.cardin Avatar answered Sep 18 '22 10:09

riccardo.cardin