This is not a new concept first of all and it is a thing that you see in your daily life as well, it is not specific to one programming language. It is a way how you organize your code, it is not like specific thing for Ruby or PHP or for JAVA or for Swift, it is just a way of how you organize your code and trust me you also see this kind of pattern every single day in your life.
Lets just assume that YOU go to some restaurant now what you do at the restaurant you don’t just go to the kitchen and make food by yourself, you just wait for a WAITER to come on, now waiter comes to you and you order the food to the waiter!
now waiter is not aware who you are or what you want to have! it just get that from you, now whenever you tell the waiter that Yes! i want this! the waiter just gets the order and now waiter moves to the kitchen.
Now in the kitchen waiter is not going to prepare your food, the food is prepared by the COOK. Now waiter will tell the cook that Hey! this the guy out there and he wants this kind of food.
Now cook is the guy who is going to prepare the food for you but cook did not cook the food magically he needs some ingredients to cook the food. he’ll open up the FRIDGE and put out something let just say you order an omelet so he’ll get the egg, sugar whatever it needs, now cook will cook the food and finally handover the food to the WAITER and probably the cook might handover the couple of other foods as well like may be a bowl of soup or french fries, now its the job of waiter to move those food outside the kitchen now waiter is actually aware that what kind of foods need to be served to you and how it should be served so waiter comes back to you and order is now served.
So you might be wondering hey this story is all about and probably you might have guess that but this is all your Model-View-Controller.
You -> View
Waiter -> Controller
Cook -> Model
Fridge -> Data
So this is a cool example and this is kind of thing you see every day. Now this is important for you to understand how this is applied to the code.
MVC is a design pattern, how you arrange your code and its going to be possible everywhere you might want to write an application in PHP, SWIFT, Ruby, JAVA you can just arrange your code.
We are trying to reduce the dependency of each code and among the different files, if some data is being passed on this file it just process this data it shouldn’t be worried about from where this data is coming from or there shouldn’t be any dependencies between these codes. it just needs the data fetches the data that in our example we can see that our cook is not actually worried about who is ordering the food, is it a teacher or a student, driver or pilot he doesn’t really care he just gets the order and cook the food and that is actually a dumb way of separating the people each other now this is the basic example. Let me tell you one more thing that this kind of approach although is good in most places but in some places it can be opposite of that, like For Example!
If there is a shop which just sells the chocolates it would be really a bad approach to you use model-View-Controller there, because there is only one job to do just bring up the chocolate and serve it. That is it!
If you will use the model-View-Controller here it will be the overuse of resources and overkill. So at some point of time model-View-Controller is not a good approach But in most of the cases where application is pretty big then its a good idea to use Model-View-Controller approach. In real life example your DATA is something fetching up from an API request or firebase and your MODEL is the guy who process the data and finally CONTROLLER should be responsible form taking that data filtering the request, the job of the VIEW is just to arrange data which is just being passed on by the controller.