Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

MVC MVVM MVP

.pdf
Скачиваний:
7
Добавлен:
17.02.2016
Размер:
164.43 Кб
Скачать

Enterprise Level Applications

Course # EGR348

Lecture #4

KBTU, Almaty

Web presentation patterns

1. MVC, MVP, MVVM.

2. Controller pattern.

Previous lecture

KBTU, Almaty

Presentation layer

The Presentation Layer contains

User Interface components. These are the visual elements used to display information and accept user input.

Presentation logic components. Defines the logical behavior and structure of the application.

KBTU, Almaty

Presentation Layer

Examples of server side frameworks

ASP.NET MVC Framework

Struts, Spring MVC (Java)

Ruby on Rails (Ruby)

Django (Python)

Symfony (PHP)

Grails (Groovy)

KBTU, Almaty

Presentation Layer

Examples of client side frameworks

JavaScript: Dojo, JQuery, ExtJS, AngularJS, Twitter Bootstrap, Backbone

Flex

Java applets

JavaFX

KBTU, Almaty

MVC

Specific patterns such as the Model-View-Controller (MVC) and Model-View-Presenter (MVP) are commonly used in presentation layer design. The main benefit of the patterns is to separate data, presentation, and actions.

MVC have two principal separations: separating the presentation from the model and separating the controller from the view. Model-View-Controller pattern is widely used for UI development. The Model manages the behavior and data, responds to requests for information about its state, and responds to instructions to change the state (usually from the Controller).

The Controller reads the mouse and keyboard inputs, informing the Model or the View.

The View code only talks to the Controller code. So that different Views might be created with the same Model or Controller.

KBTU, Almaty

MVC

Web application

User interaction

Controller

View Model

Fig.1. Model-View-Controller pattern.

KBTU, Almaty

MVC

The event flow is

1.User send request to C. C: Select the action.

2.C: Action calls to change M.

3.C: Fire event that M is changed.

4.V ask for data from M.

5.M send data to V.

6.V renders the data into HTML and send back to user.

The main disadvantage of MVC is that each component is rendered each time the user fire event.

Fundamentally presentation and view are about different concerns. When you're developing a view you're thinking about the mechanisms of UI and how to lay out a good user interface. When you're working with a model you are thinking about business policies, perhaps database interactions. Certainly you will use different very different libraries when working with one or the other. Depending on context, users want to see the same basic model information in different ways. Separating presentation and view allows you to develop multiple presentations. Nonvisual objects are usually easier to test than visual

ones. KBTU, Almaty

MVP

Web application

User interaction

Presenter

View

Model

Fig.2. Model-View-Presenter pattern.

KBTU, Almaty

MVP

MVP separate request processing into three roles, with the View being responsible for handling user input, the Model is responsible for application data and business logic, and the Presenter is responsible for presentation logic and for coordinating the interaction between the View and the Model.

The event flow is

1.User send request to V.

2.V notify P. P. select the action.

3.P: update the M.

4.M returns data to P.

5.P: generate HTML.

6.V send data to User.

Presenter and View should have a 1-1 relation. But in MVC, different views may have a single controller.

View is responsible for delegating the user input to Presenter.

For multicomponent page MVP is much better compared with MVC.

KBTU, Almaty

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]