0% found this document useful (0 votes)
11 views

MVC

The Model-View-Controller (MVC) design pattern separates applications into three components: Model (data and business logic), View (user interface), and Controller (intermediary between Model and View). This separation enhances code organization, maintainability, and scalability, addressing issues of intertwined code in traditional development. While MVC offers benefits such as easy management and teamwork, it may be overly complex for small projects and can complicate debugging.

Uploaded by

Nour Abdallah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

MVC

The Model-View-Controller (MVC) design pattern separates applications into three components: Model (data and business logic), View (user interface), and Controller (intermediary between Model and View). This separation enhances code organization, maintainability, and scalability, addressing issues of intertwined code in traditional development. While MVC offers benefits such as easy management and teamwork, it may be overly complex for small projects and can complicate debugging.

Uploaded by

Nour Abdallah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Design patterns :

(MVC)

By : Nourhan Abdallah
Agenda
❑ Description
❑ Problem
❑ Solution
❑ Class structure
❑ Example from real life
❑ Sample code
❑ Another example
❑ Pros
❑ Cons
❑ Conclusion
❑ References
Description

• The Model-View-Controller (MVC) design pattern is a


fundamental concept in software engineering, particularly in
building user interfaces. It separates an application into three
interconnected components, enabling better organization,
maintainability, and scalability of code .
Problem

• In traditional software development, the code for handling user


interfaces, data manipulation, and business logic tends to get
intertwined. This lack of separation leads to difficulties in
managing and modifying code, increasing the risk of bugs and
hindering collaboration among developers.
Solution

MVC solves this problem by dividing the application into three interconnected components:

• Model: Represents the data and business logic of the application. It manages the data, responds to requests
for information, and notifies the views of any changes.The backend that contains all the data logic

• View: Presents the data to the user and handles user interactions. It receives data from the model and
renders it in a user-friendly format. Views also send user input back to the controller for processing. The
frontend or graphical user interface (GUI)

• Controller : Acts as an intermediary between the model and the view. It receives user input from the view,
processes it (often by updating the model), and updates the view accordingly.

• The brains of the application that controls how data is displayed


Class Structure:

• Model : Contains data and

business logic methods.

• View : Renders the user interface

and sends user input to the controller.

• Controller : Handles user input,

updates the model and updates the view.


Example :
Scenario:

• View: Shows the post and reactions (Like,


Love, etc.)
• Controller: Handles the user clicking "Like"
• Model: Stores the number of likes
1.Role of PostModel in MVC:

This is the Model part of the MVC pattern.Its job is to manage the data, keep
track of the likes, and handle business logic (like updating the number of
likes).It doesn't care about how the data is shown or how the user interacts.
1. Model – Stores post data
2. View – Displays the post and like count

Role of PostView in MVC:The View is responsible for presenting information to the


user.It doesn’t deal with data or logic — it only shows what the app wants the user
to see (output/UI).So, in this case, PostView just prints things like:The number of
likesThe reaction options
Role of PostController in MVC:

The Controller acts as a middleman between:View (what the


user sees)Model (where the data is stored)It listens to user
actions (like clicking "Like"), processes them, and updates
both the Model and the View accordingly.
4. Main – Simulate user browsing and reacting

This is the entry point of your program — it


creates the Model, View, and Controller,
and simulates how a user would interact
with the system (like browsing Facebook
and clicking "Like").
Result

What You've Built:

You've just created a working MVC structure in


Python that:

• Cleanly separates data (Model), user interface


(View), and logic (Controller)

• Can be easily extended (e.g., add more reactions,


comments, or even a GUI)
Sample code :
2. View

1. Model
Example :

3. Controller
Pros of MVC
1. Easy to Manage
Everything is organized — data, design, and logic are in separate boxes.

2. Easy to Update
You can change the look (View) without touching the logic (Controller) or data (Model).

3. Teamwork Friendly
One person can work on the design, another on the data, and another on the logic — all at the same time.

4. Reusability
You can reuse the same code for other apps or parts of your project.

5. Good for Big Projects


Helps keep large applications clean and well-structured.
Cons of MVC:

1.Too Much for Small Projects

If your app is simple, MVC might feel like extra work.

2.Hard to Learn at First

It can be confusing to understand how Model, View, and Controller work together.

3.More Files and Code

You need to write more code and manage more files than usual.

4.Debugging is Tricky

Since things are separated, it can be harder to find where a problem is coming from.
References

• The Model View Controller Pattern – MVC Architecture and Frameworks Explained

• MVC Design Pattern | GeeksforGeeks


Thank You

You might also like