Definition
The Model layer is responsible for data access and business logic in UI architectural patterns.
flowchart TB M[Model] M --> D[Data Access] M --> B[Business Logic] M --> S[State Management] D --> DB[(Database)] D --> API[API Layer] D --> Cache[Cache]
Responsibilities
- Data Access: Interfaces with databases, APIs, and data sources
- Business Logic: Contains domain rules and validation
- State Management: Manages application state and data consistency
Key Characteristics
- Independence: Model has no knowledge of View or Controller/Presenter
- Reusability: Can be shared across different Views
- Testability: Easy to unit test in isolation
- Single Source of Truth: Maintains consistent data state
Interactions
The Model communicates only with the translator component (Controller, Presenter, Interactor, or ViewModel) and never directly with the View. This ensures:
- View cannot corrupt business logic
- Changes to UI don’t affect business rules
- Model can be tested independently
Pattern Usage
| Pattern | Model Role |
|---|---|
| MVC | Updated by Controller, notifies View (Active View) or provides data to Controller (Passive View) |
| MVP | Updated by Presenter, returns data to Presenter |
| MVVM | Updated by ViewModel, observed via data streams |
| VIPER | Managed by Interactor, contains Entities |