The single-responsibility principle (SRP) says that each class or method should have one purpose, with every part aligned to that purpose. In application architecture, separating UI, presentation, and business responsibilities reduces coupling and makes changes easier to isolate. section 9.4 section 9.3
Apply SRP in an MVVM architecture by assigning each concern to its proper component:
- Keep layout and UI behavior, such as markup, animation, and formatting, in the View. section 9.3 section 9.3.5
- Keep UI state and presentational logic, such as bound properties and responses to user actions, in the ViewModel. section 9.3 section 9.3.5
- Keep domain objects, processing rules, and database or API operations in the Model and its services. section 9.3 section 9.3.5
MauiStockTake without MVVM
A UI that gathers control values, constructs service requests, manages application state, and executes business logic violates SRP. The result is tight coupling, difficult maintenance, and business logic that is almost impossible to test except manually. Moving state and commands into a ViewModel and business operations into the Model separates those responsibilities. section 9.4
Figure 9.7 In the MVVM pattern, the View only contains UI logic. Controls are bound to properties on a ViewModel, and rather than event handlers, commands are used to trigger actions. The ViewModel maintains the state of the View by exposing properties for the UI to bind to and commands for the UI to call. The Model contains all the business logic, and the ViewModel interacts with the Model. In this example, a CarService from the Model is injected into the ViewModel. A Button in the View is used to trigger a command in the ViewModel. The ViewModel contains a Car object, which has properties bound in the UI. The Add Car Command calls the AddCar method in the injected service and passes in the ViewModel’s Car property as a parameter.
Trace how a car application divides responsibilities: the View binds controls, the ViewModel exposes state and commands, and an injected CarService performs business operations. section 9.3.5






