Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does it make sense to abandon MVVM?

Tags:

mvvm

wpf

As I've been learning WPF, I've been concentrating on applying only the MVVM pattern to applications.

However, I notice that for some functionality such as validation, it is difficult or impossible to remain true to the MVVM model. Many times simply sticking an x:Name on an element and changing it in code-behind event-handler solves the problem immediately.

What real world experience do you have with abandoning the MVVM pattern?

  • when does abandoning MVVM make sense? e.g. have you developed rules that if an application is of a certain complexity you will use it, otherwise you won't?
  • when does it abandoning MVVM cripple you later (e.g. I can imagine if you want to upgrade your application to use Composite Application Library, the whole concept of injecting ViewModels and the Container won't work if you have all your logic in code behind
  • when does abbandoning MVVM not matter, e.g. I can imagine that code that you don't want/need to have tested can just be in the code behind while your basic structure is still MVVM and gets run through mock tests, etc.
like image 486
Edward Tanguay Avatar asked May 28 '09 16:05

Edward Tanguay


People also ask

Is MVVM an overkill?

MVVM creator John Gossman points out that implementing MVVM is "overkill" for simple UI operations, and that for larger applications, generalizing the ViewModel becomes more difficult. There is considerable memory consumption with data binding in very large applications.

Should I always use MVVM?

For trivial projects MVVM is unnecessary. Using only the View is sufficient. For simple projects, the ViewModel/Model split may be unnecessary, and just using a Model and a View is good enough. Model and ViewModel do not need to exist from the start and can be introduced when they are needed.

What is the disadvantage of MVVM?

Disadvantages of MVVM Model:This can confuse the developer and make the development or debugging process complicated. When it comes to an Android environment, the user is restricted with only two ways to work with View. Moreover, they can either use Data Binding or any other View method.

Does WPF need MVVM?

The Windows Presentation Framework (WPF) takes full advantage of the Model-View-ViewModel (MVVM) pattern. Though it is possible to create WPF applications without using the MVVM pattern, a little investment in learning can make building WPF applications much simpler.


1 Answers

I think code-behind is fine if it's view related only. It doesn't break MVVM because it's the separation of the layers what is important. If your VMs stay unaware of the Views, then I don't think it matters if you used XAML or code. You try to minimize code-behind because it's usually cleaner and easier to do in XAML, but sometimes a few lines of code are cleaner than a lot of XAML. For example, binding all the keys of the keyboard. You can type 101 key bindings in XAML or 5 lines of code.

like image 96
Carlos Avatar answered Oct 03 '22 08:10

Carlos