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:

  1. View cannot corrupt business logic
  2. Changes to UI don’t affect business rules
  3. Model can be tested independently

Pattern Usage

PatternModel Role
MVCUpdated by Controller, notifies View (Active View) or provides data to Controller (Passive View)
MVPUpdated by Presenter, returns data to Presenter
MVVMUpdated by ViewModel, observed via data streams
VIPERManaged by Interactor, contains Entities