MVC Flashcards
(24 cards)
What is MVC?
MVC is an architectural design pattern that divides an application into three main components:
Model(manages the core data and business logic),
View(responsible for displaying data to the user),
Controller (handles user input, updates the Model, and refreshes the View).
Components & Responsibilities: Model
Represents application data and state (e.g., account balances, transaction history). Enforces business rules and maintains data consistency. Notifies the View of data changes to update the display.
Components & Responsibilities: View
Presents data from the Model visually. Reacts to changes in Model by updating the user interface. Does not contain business logic; purely a presentation layer.
Components & Responsibilities: Controller
Acts as a mediator between Model and View. Processes user inputs (e.g., button clicks, form submissions). Updates Model based on inputs and coordinates updates to the View.
Core Principles: Separation of Concerns
Each component focuses on a distinct responsibility to reduce code overlap and complexity.
Core Principles: Modularity and Maintainability
Changes in one component (e.g., Model) don’t directly affect others, enabling easier updates and extensions.
Core Principles: Scalability
New features can be added by extending Models, Views, and Controllers without disrupting existing code.
Core Principles: Flexibility
Supports multiple user interfaces (e.g., mobile, desktop) sharing the same Model but with different Views.
Core Principles: Testability
Components can be tested independently (Model logic, Controller input handling, View display), improving reliability.
Terminology and Relationships: Model-View Relationship
View observes Model changes but does not modify data directly.
Terminology and Relationships: Controller-Model Relationship
Controller interacts with Model to apply business logic and update data.
Terminology and Relationships: Controller-View Relationship
Controller updates View to reflect Model changes.
Terminology and Relationships: No direct View-Model interaction
Communication is typically through Controller to keep components decoupled.
Terminology and Relationships: Passive View
The View is passive and driven by the Controller, meaning it does not contain logic for data manipulation.
Example Context (Banking App): Model
Stores account details, transaction history.
Example Context (Banking App): View
Displays dashboards, transaction lists.
Example Context (Banking App): Controller
Handles user actions like money transfers, updating balances.
UML Application Notes: Classes
Separate classes clearly into Model, View, and Controller in class diagrams.
UML Application Notes: Methods
Align methods between sequence diagrams and class diagrams for clarity.
UML Application Notes: Naming
Use clear method naming to reflect Controller responsibilities (e.g., initiateTransfer(), validateTransfer()).
UML Application Notes: Responsibilities
The Controller orchestrates the flow, Models handle data, Views display information.
Final Notes: MVC nature
MVC is a guideline rather than strict rules, adaptable per project needs.
Final Notes: Focus
Focuses on improving maintainability, testability, and scalability through clear role separation.
Final Notes: Variants
Variants of MVC exist due to its evolution over time.