13
MVC, MVP, MMVM, ... Or how I stopped worrying and learned to separate logic and representation

Mvc, mvp, mvvm

Embed Size (px)

Citation preview

Page 1: Mvc, mvp, mvvm

MVC, MVP, MMVM, ...

Or how I stopped worrying and learned to separate logic and representation

Page 2: Mvc, mvp, mvvm

Motivation?

The MVC separation helps you manage complex applications, because you can focus on one aspect a time. For example, you can focus on the view without depending on the business logic. It also makes it easier to test an application.

Page 3: Mvc, mvp, mvvm

Model

View

Controller

calls

updates

notifies

Page 4: Mvc, mvp, mvvm

The Model is the part of the application that handles the logic for the application data.Often model objects retrieve data (and store data) from a database.

The View is the parts of the application that handles the display of the data.Most often the views are created from the model data.

The Controller is the part of the application that handles user interaction.Typically controllers read data from a view, control user input, and send input data to the model.

Page 5: Mvc, mvp, mvvm

● The view objects in an application are actually a composite ● A controller object implements the strategy for one or more

view objects● A model object keeps interested objects in an application—

usually view objects—advised of changes in its state.

Classical MVC

Page 6: Mvc, mvp, mvvm

Model–view–adapter (MVA) or

mediating-controller MVCor...

MVP?

Page 7: Mvc, mvp, mvvm

Behavior of the active model

Page 8: Mvc, mvp, mvvm

Behavior of the passive model

Page 9: Mvc, mvp, mvvm

● View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.

● Easier to unit test because interaction with the view is through an interface

● Usually view to presenter map one to one. Complex views may have multi presenters.

MVP

● Controller are based on behaviors and can be shared across views

● Can be responsible for determining which view to display

MVC

Page 10: Mvc, mvp, mvvm

Presentation Model aka MVVM... is all about binding (WPF, silverlight, flex, javaFX)

Page 11: Mvc, mvp, mvvm

http://developer.apple.com/library/mac/#documentation/General/Conceptual/CocoaEncyclopedia/Model-View-Controller/Model-View-Controller.html

Sources:

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

http://msdn.microsoft.com/en-us/library/ff649643.aspx

http://stackoverflow.com/questions/2056/what-are-mvp-and-mvc-and-what-is-the-difference

http://alexander.lds.lg.ua/2010/05/mvvm-model-view-view-model-design-pattern-for-net-windows-forms-winforms/

Page 12: Mvc, mvp, mvvm

MVC in Java world

MODEL 1(not bro)

MVC MODEL 2(bro)

http://www.javaranch.com/journal/200603/Journal200603.jsp#a5

Page 13: Mvc, mvp, mvvm

The request processing workflow in Spring Web MVC (high level)

http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html