Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Business Logics of projects under MVVM in WPF?

I am developing an application in WPF using the MVVM pattern. If I have Student as a data model, for example, where could I add the business logic like adding new Students, deleting Students and updating Student info, calculating marks and so on?

Does all the business logics come under the model or the viewmodel?

If it is in the model how can we do that? Any example code please? I need full code for an example!

like image 726
nallskarthi Avatar asked Sep 15 '25 15:09

nallskarthi


2 Answers

Business logic should be part of of your model, as all of that code should be reusable across different technology platforms. For example, you may want to reuse your models across a web site in ASP.NET MVC, and a desktop application in WPF, so it wouldn't make sense to have business logic in your view models.

View models should contain presentation logic which is specific to that particular application instance.

As for example code, this will be specific to the domain that you are modelling, so you would have to ask a more specific question about what you are trying to model.

like image 58
devdigital Avatar answered Sep 17 '25 19:09

devdigital


I suggest you read PRISM documentation on this subject: Chapter 5: Implementing the MVVM Pattern.

Even if you don't plan to use PRISM, the article is very well written and details the pattern in Microsoft's technology terms.

like image 41
Simon Mourier Avatar answered Sep 17 '25 20:09

Simon Mourier