Inquiridor

MVVM/MVC

Pergunta

For thesurvey
conducted, we see thatmore
and morein
applications development,is
followed by theMVVM,what
are the advantagesof
this in relationto
MVC,since
we aremore
familiar withMVC(Model-View-Controller)?

Todas as Respostas

1. Increases the "Blendability" of your views (ability to use Expression Blend to design views) – This enables a separation of responsibilities on teams that are lucky enough to have a designer and a programmer... each can work independent of the other.

2. "Lookless" view logic – Views are agnostic from the code that runs behind them, enabling the same view logic to be reused across multiple views or have a view easily retooled or replaced. Seperates concerns between "behavior" and "style".

3. No duplicated code to update views – In code-behind you will see a lot of calls to update view controls. With MVVM you can be assured the view is updated appropriately just by setting the underlying property and all view side-effects thereof.

4. Testability – Since your logic is completely agnostic of your view, unit testing is made easy. You can test the behavior of a ViewModel without involving its view. This also enabled test-driven development of view behavior, which is almost impossible
using code-behind.

5. Designer-Developer Workflow – MVVM facilitates a separation of UI and presentation logic concerns from the business layer that makes it easy to streamline the development process by allowing design cycles to happen in parallel with development.

The MVVM pattern was introduced by Microsoft Architect John Gossman as a WPF and Silverlight specialization of Martin Fowler’s platform-independent Presentation Model (PM) pattern (a variation of MVC).

The key difference is the existence of binding to decouple the 'View Model' from the 'Model'.

It comes down to what "application" you are building. MVVM web applications frameworks like KnockoutJS have peculiar advantages including a closer UI centric viewmodel abstracted from HTML and faster page loads when used with MVC4 WebAPI. I suggest reading
Addy Osmani's blog on KnockoutJS

As already mentioned, these are patterns NOT technologies. In theory you can use MVVM or MVC on a ZX Spectrum (ask your parents). Whilst it's true that MVVM has become popular with XAML based technologies it's also true that it's been implemented elsewhere
as Vinod as already mentioned. They are both patterns that promote separation between what is showing some data, what is holding the data and what is orchestrating the whole. I like MVVM for the reasons already provided (although some mentioned
above are not MVVC over MVC, the share a great deal), but it does depend on what you are writing, and unfortunately, what tools/technologies you are using as practically that will impact your ROI.