What is MVC (Modal, View, Controller)?
Modal, View, Controller (MVC) is the most popular architecture pattern that separate an application into three main logical components which are:-
- The Modal
- The View and
- The Controller.
MVC stands for Modal, View, Controller, it is used to define how these three entities can interact with each other. This is not new concept first of all and it is a thing that you see in your daily life and also this not specific to one programming language.
It is a way of how you organize your code, it is not like specific thing for a Ruby or PHP or for Java or for Swift or for Python or for C++, it is a just a way of how you organize your code.
Most people believe that the Modal, View, Controller is for PHP or for Ruby or for Java but it is not, it’s a design pattern how you arrange your code and it’s going to be possible and everywhere you might want to write application in PHP or Java or Python or Ruby.
Now the main advantage of this MVC approach is you can write the dumb code and the more the code is going to be dumb it is going to be more beneficial, what I mean by that we are trying to reduce the dependency of each code and this files from each other we want that 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 up, it just needs the data fetching the data and that is it.
Example in ordering food, Cook is not actually worry about who is ordering food is it male or female, is it kid or may be grandfather, he doesn’t really care, he just gets the order and cooks the food.
This kind of approach (MVC) although is good in most places but in some places it can be opposite of that like for example if there is store which just sells the popsicles or ice creams it would be bad approach if we use a Modal, View, Controller (MVC) there because there is just one job to do just bring ice cream from the fridge and serve it, if you use Modal, View, Controller (MVC) approach will be overused and overkill of the resources so at some point of that time MVC is not good approach, but in most cases where application is pretty humongous pretty big then it is good idea to use MVC approach.
Modal is not the data, it handles data validation and logic, it interact with the database. The data is completely separate it needs to be cooked up. In real life example your data will be something fetching from an API request or may be from the firebase or wherever you guys fetching your data. But the Modal should process the data.
Controller should be responsible from taking the data filtering the request, example let us say you asked the result of top ten (10) wonders in the world, it is a job of Controller to filter out the data and produce that on the View.
View, the job of the View is to arrange those data which is being passed on from the Controller and that is.