What is MVC?
Advantages of MVC framework
MVC is stands for Model-View-Controller and is pretty much how an application can be designed. It is not required when building an application, but is a format that you may come across while building applications. Each part interacts with each other and has a particular use.
The Model stores data (usually from your database) and handles the logic.
It represents data that is being transferred between controller components or any other related business logic.
In a simple Sinatra app, this is where you will inherit ActiveRecord::Base and your activerecord associations. In addition, you would set and authenticate against a BCrypt password inside of the models class .
The view is where the user can input information and is what the user can see. So usually your
.html files. It is everything your user sees and interacts with when visiting your application.
The Controller is the middleman. It handles and updates both the models (database) and views(user input). It can accept user input and perform CRUD actions. What is CRUD? CRUD is Create, Read, Update, and Delete -- I have reviewed CRUD in past posts. But I feel like this code academy article puts it all together.
Do you remember RESTful routing? Well, the Controller interacts with the views to ensure restful routing is successfully used for user accessibility and our sanity.
In short, with MVC everything interconnects --
The model handles the data (usually from the database), the view is the user interface, and the controller processes all of the inputs from the database and the user interface.
- Saves Time and effective use of resources – saving time, money, resources and managing the resources effectively.
- Facilitates multiple views, separates data, and makes duplication of code is certainly less.
- Modification does not affect the entire model
- SEO Friendly Platform providing ease to develop SEO friendly URL’s in order to generate more visits on a specifies pages.
Be sure to keep in mind that although MVC is a great tool and design to use, it is not the only way to build an application and not everything will necessarily fit into the MVC design. For example, while building my application I needed a different class for my API manager that was not necessarily a model, view, or controller. It is okay to create your own classes and to do what is best for your particular needs.
Song of the day: