He says that if we want to change any thing in the view, for example, change a button or any control, then this can be done directly in the code. Why use MVVM?
Of course, this can be done like this. The question is whether this should be done in this way.
For a fairly small code base, you can probably avoid mixing data access, core logic, and user interface manipulation in the code. In the long run, however, this will not do for supported or verifiable code, and the mess will probably get worse over time and turn into spaghetti code. Take my word for it, because most of my time at work is put in the opposite direction of such old riots.
Some consequences of mixing all the code in the code:
- Code that fundamentally violates the “Single Responsibility Principle” (SRP).
- Code that is hard to understand because it does different things in the same place.
- Code that breaks easily. I'm changing something here and for some secret reason, there are some functions.
- Code duplication / Do Not Repeat Yourself (DRY) violation. You often find the same logic in several places. Is it random or intended? If I change the logic here, should the same / similar logic be changed too?
Please note that with the exception of the first point, these are not theoretical problems, but very real, immediate problems of your typical "old" code base.
In my opinion, it is not entirely correct to say that MVVM introduces more code classes. This is clearly an expression from someone who does not understand the fundamental separation of the problems that arise when you isolate the data, business logic and logical levels of the UI from each other: even with MVVM you only have one code class for your views. The other two classes (yes, most likely, two more) simply cannot be considered "code", because they are not directly tied to the presentation / design.
source share