Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When NOT to use MVVM?

I have started using MVVM pattern recently. I have had several projects where I used it and with every new one, I start to see that it will fit great within that new project.

And now I start to ask myself are there situation when it's better NOT to use MVVM. Or is it such a nice pattern which you can use anywhere?

Could you please describe several scenarios where MVVM wouldn't be the best choice?

like image 415
Vitalij Avatar asked Jan 10 '11 14:01

Vitalij


4 Answers

I can think of two circumstances under which I wouldn't use MVVM.

One is if the application's simple enough that I don't need a separation between the view model and the model. Does it muck up my class too much if I implement INotifyPropertyChanged and a RelayCommand or two? If not, I might skip the step of creating a separate class. Or I may just want a view model to mock up a functional UI, and worry about implementing actual back-end functionality if the client bites.

The other is when I need high enough performance, and there are enough objects in the view, that I need to write code that manipulates WPF objects directly. I haven't actually benchmarked it to be sure, but I'm be reasonably certain that drawing 1000 moving particles by iterating through an array containing them and modifying their TranslateTransform directly (if indeed that's the fastest way to position them) is going to be faster than modifying their base properties and having binding do it.

like image 106
Robert Rossney Avatar answered Oct 23 '22 19:10

Robert Rossney


I only do not MVVM if its a tool that is not used more than at a specific moment and then never ever.

In many "small" projects, I have begun without, and later on, I have changed to MVVM. It makes the projects IMO much more clean and gives all my projects a similar structure. This helps me a lot to change quickly some things in some elder code if a client has a small request. I don't loose much time to me orientate.

Another advantage is that it's easier to hold my libraries clean, because I can focus on one technique and have therefore more time to maintain and extend.

like image 32
HCL Avatar answered Oct 23 '22 19:10

HCL


It all depends on what you want to do.

Like the guys have said, if you are creating a small tool or project that will not need extensive testing etc then MVVM would be overkill.

Arguably MVVM's main advantage is that it makes the code unit testable as it abstracts away from Visual Layer. For large projects that need to be reliable and are to be used by customers etc (and not just yourself as the end user) then MVVM is a good design pattern to use.

I guess in a nutshell - if you are simply creating a small project to mess around with then MVVM would be like trying yo kill an ant with a bazooka :)

like image 33
GaryT Avatar answered Oct 23 '22 20:10

GaryT


For me it's best to not use it when you want to do a small project or never plan to make it run under several ways (WPF/Silverlight/WEB/Dll), then MVC is enough.

like image 24
ykatchou Avatar answered Oct 23 '22 20:10

ykatchou