DEV Community

Fortunatus Adegoke
Fortunatus Adegoke

Posted on

Explain MVC Like I'm Five

I need someone who can explain MVC concept to me like a layman.

Top comments (8)

Collapse
 
nestedsoftware profile image
Nested Software • Edited

It's the idea of separating pieces of logic in the presentation layer (i.e. user interface) part of your code to make their responsibilities more clear. The view is the part of the code that actually shows the user interface. For example, it might be a form the user fills out. The model is where the data for the form is actually stored while the user is filling the form out. The controller manages the interaction between the view and the model. In other words, it picks up the user typing into the view component and tells the model to update itself with that content. There are some variations, but the basic idea of separating these types of things out when coding user interfaces tends to be a very common pattern.

Collapse
 
fortunatus profile image
Fortunatus Adegoke

Thanks so much @nestedsoftware

So M Stands for models: "Data storage, more like the database."
V stands for views: "What is displayed to the user interface"
C stands for controllers : "Like a middle man between views and models."

So this are what I need to focus on for creating an API?.

Collapse
 
nestedsoftware profile image
Nested Software • Edited

I think MVC is more common on the front-end (e.g. code that runs in the browser). On the server side it is used by frameworks like Spring MVC that display the user interface as JSP pages from the server, but less so for cases where the front end is a React application (or some other type of single-page-application, aka SPA, such as Angular)... To implement a back-end API REST endpoint, I don't think you'd use MVC...

Thread Thread
 
fortunatus profile image
Fortunatus Adegoke

Okay, got it fully well.

Thanks for your time.

Collapse
 
prsaya profile image
Prasad Saya

So this are what I need to focus on for creating an API?

You can use an API to read data from the view or update the view with new data. The API is the code that can connect to the view as well as connect to the data store for CRUD (Create, Read, Update and Delete) operations.

Collapse
 
entrptaher profile image
Md Abu Taher

I asked ChatGPT.

Explain MVC Like I'm Five

Okay, here's a simple way to explain MVC to a five-year-old:

MVC is like a game where you have three different characters, each with a special job to do.

  • The Model character is like a teacher. They know a lot about a subject, and they can help other characters learn new things.
  • The View character is like an artist. They can draw pictures and make things look nice and interesting.
  • The Controller character is like a conductor. They help the other characters work together and make sure everything goes smoothly.

Together, the Model, View, and Controller characters make up a team that can help each other out and make sure the game is fun and works well. That's kind of like how MVC works in a computer program. It helps to keep things organized and working together, so that the program can do what it's supposed to do.

Collapse
 
rahxuls profile image
Rahul

MVC stands for Model-View-Controller. It's a way of organizing the different parts of a program, like a game or an app. The model is the part of the program that holds the information and data, like a list of words in a dictionary app.

The view is the part that shows the information to the person using the program, like the screen of your phone that shows the words in the dictionary app.

The controller is the part that helps the model and the view talk to each other, and makes sure that everything works together smoothly.

So, MVC is like a team of three friends who all have different jobs to do, but they work together to make the program run well.

Collapse
 
jahid6597 profile image
MD. JAHID HOSSAIN

MVC is like playing with toy cars!

You have a toy car (the Model) that you can push around and make it move. You also have a remote control (the Controller) that tells the car what to do.

Now imagine you want to make a cool race track (the View) to show off your toy car to your friends. You can use a big piece of paper to draw the track and put some obstacles on it, so your friends can see your car racing around.

So, in MVC, the Model is your toy car, the Controller is your remote control, and the View is the cool race track you made. Just like you can play with your toy car using the remote control and show it off on the race track, developers use MVC to make programs work and look good for users!