Contents
Can we write business logic in ViewModel?
ViewModel: ViewModel is the middle layer between the view and model. ViewModel contains the business logic, which manipulates the row data to show in the view. Any kind of function and methods should be in the view model. The iNotifyPropertyChanged interface is used in the ViewModel to achieve two-way binding.
What is MVC business model?
A1: Business Logic goes to Model part in MVC . Role of Model is to contain data and business logic. Controller on the other hand is responsible to receive user input and decide what to do. A2: A Business Rule is part of Business Logic . They have a has a relationship.
What does ” business logic should be in a service “?
In reality, what a service ought to do is highly architecture-specific: In a traditional layered architecture, service is literally synonymous with business logic layer. It’s the layer between UI and Data. Therefore, all business rules go into services.
Where does business logic go in a model?
Therefore, business logic by definition goes in the Model, not the ViewModel. The job of the ViewModel is to expose properties and fields of the Model, and prepare them for consumption by the View. For instance, picture a banking application. The Model may represent an account. Perhaps the Model has an account balance.
Which is the correct life circle for business logic?
My suggestion is to put logic in a service layer instead. This is a middle layer between view model and model (which, in a real object oriented paradigm, should only contains properties). So the correct life circle may be: View model -> service -> model handling. This allows also to reuse business logic code through others view model if needed
How much business logic should be allowed in the controller?
If there is business logic shared between controller and model the two layers are no longer separable, and someone inheriting the code may be confused by this unevenness in location of business logic related code. My question is how much business logic should be allowed in the controller and in what circumstances, if any?