The Model Component
The Model represents the underlying data structure and state of an application, along with the business logic that governs it. It has no direct knowledge of how the data will be presented to the user (the View) or how user input will be processed (the Controller).
Responsibilities of the Model
- State Maintenance: Storing and maintaining the central state and data variables of the application.
- Data Retrieval and Persistence: Accessing files, database tables, or external web APIs to retrieve or save data.
- Business Logic Validation: Ensuring that database operations and state updates conform to predefined rules (e.g., checking if an age is positive or email format is valid).
- Notification: Informing registered observers (Views) of state changes so the interface can update accordingly.
Five Examples of Data Managed by the Model
In a typical system (such as a university portal or ecommerce app), the Model manages the following key data points:
-
User Account Profiles:
- Contains data fields: Full Name, Email, Password Hash, Contact Number, and Account Type.
-
Student Academic Grades:
- Contains data fields: Student ID, Course Code, Subject Names, CGPA, and Marks.
-
Class Timetable Schedules:
- Contains data fields: Weekday, Time Slot, Course code, Location, and Instructor Name.
-
Product Inventory Items:
- Contains data fields: Product ID, Name, Category, Unit Price, Stock Count, and Description.
-
Customer Order History:
- Contains data fields: Order ID, Customer ID, Date, List of Products purchased, Total Price, and Order Status.