mvvm concept in software design – model view view model?

843 views

I literally studied computer science and don’t understand this. I’m so frustrated.

In: Technology

3 Answers

Anonymous 0 Comments

You have an object which contains all your data (Model) . And a view which displays all your data.
With normal mvc (model View controller) your object with data does not know when a value is changed in your view (E.g. You select your age, the object does not know you set.
With mvvm the model listens to the view, and the view listens to the model. That way if you update age in the view, the model will be updates with your selected age, and vice versa.

Anonymous 0 Comments

View: Account screen with user name, user photo, and list of user’s posts

Model: Users table, media library table, forum posts table

View Model: Gets data from the Models, combines it into useful info for the View. Maybe sets the default profile image if user doesn’t have one, or passes “Not Set” if the email hasn’t been provided.

Also think of it as…

View: dumb, what the user sees and touches

Model: dumb, the data

View Model: smart, business logic that passes, sanitizes, etc data between the two dummies above

Anonymous 0 Comments

Are you asking this purely out of curiosity or because of a job?

MVVM isn’t extremely popular in my experiences any longer, but older applications will use this design. It is very good for ‘Single Page Applications’. Here’s my explanation in comparison to MVC which I have alot of experience with. Hope it helps.

If you are familiar with the basics you know the model houses all of the fields/properties and typically a few type specific methods like maybe a ToString override. The view is merely the presentation, what the user will see. Here is where MVC and MVVM differ. .

In MVVM there is no controller. Most, if not all, properties on a model are bound to an object on the view. Example would be a text field called name. If the user types “Mike” on the view the model will get that information immediately. In MVVM the model will also be responsible for all event driven actions. If a user clicks Save for instance, the model will house atleast the entry point for this action. It essentially removes the need for a controller by inserting direct communication between the view and model and adding responsibility to the model.

MVC which I much prefer has a controller which house all of the ‘actions’. In essence a controller is constantly ‘listening’ for the user to do something. In this design there is no communication between the model and view. Model only houses the data. View only displays the data. The controller lies inbetween and does all of the work. For instance in this example if a user types the name “Mike” into the same textbox the model will have no knowledge of this until the controller is informed via an action on the view. A simple example is the user types into a text field on the view. A Save button is pressed which then passes the value in the text field to the controller. The controller will do something with that information, possibly update the model, and pass the new model to the view.

I know I didn’t explain this like you were 5 lol, but it’s not something a 5year old could understand. I know you didn’t ask this, but in my opinion MVC is the clear winner for all the applications I’ve worked on, however I have worked exclusively with Web Apps.