Should Viewmodel Contain Logic?

Should Viewmodel Contain Logic?

1 Answer. Short answer, Yes.

Should ViewModel have logic?

The job of the ViewModel may be to turn the balance into a string that is used as a binding in the View. You want to keep as much logic out of the ViewModel as possible to keep your code reusable and loosely coupled. I disagree with this. A model should ideally only have properties because models represent the data.

What should a ViewModel contain?

The simplest kind of viewmodel to understand is one that directly represents a control or a screen in a 1:1 relationship, as in "screen XYZ has a textbox, a listbox, and three buttons, so the viewmodel needs a string, a collection, and three commands." Another kind of object that fits in the viewmodel layer is a ...

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.