MVC
Hey, everyone, it’s me Danny here with my first blog post. In case you haven’t read the title yet today’s topic is MVC. So the question is what is MVC? well MVC is an application design model focused on the separation of concerns. In other words, it helps you structure your code into three major sections Model, View, and Controller. Each section has a role to play we’ll get into that in the following sections.
M
The M stands for Model sometimes referred to as (data). The model is where you are going to be handling data this also includes client data and writing most of your code. When I say you’ll write most of your code in the model this is referring to writing business logic and your apps main functionality. The model will also house your association’s ex(belongs_to, has_many, etc.) and validations. Below is a picture of a model
v
The V stands for View and like the name suggests it’s purpose is to deal with anything involving the view. This means anything from putting some text on the page to structuring the basic user interface for our webpage. Depending on the language you’re using you might accomplish this is using ASP, ASPX, JSON, HTML, CSHTML, or VBHTML. Most webpages use HTML and then style with CSS later. When writing in the view section keep in mind that goal is to focus on the webpage’s visual outcome. So if you find yourself writing code here that does not affect the visual outcome of the webpage chances are there is a better place to put it.
c
The C stands for Controller which I believe to be one of the most important parts since without the controller the view and model would not be able to communicate. The controller does many things but its main task is to serve as a middle man for user input, models, and views. A real-world example I learned at Flatiron is the restaurant example. The restaurant is the whole MVC structure. The waiter(controller) takes orders(inputs) from the customer(user) and sends them to the chef(model). Once the chef is done making the food the waiter takes the food to the customer’s table(view) that’ll hold the food.
These are some companies you might know that use MVC for their webpages.
I’ve linked their webpages if you want to take a look at them. The reason I’m telling you that about these webpages is so that you can see what the MVC structure can turn in to as an end result. Before we end here are some benefits of using MVC besides structuring your code. Faster development time, you can use multiple views. etc..
Conclusion
This briefly covers the MVC architecture Model, View, and Controller. This is a very developed concept that is widely used — you can find more in-depth information in the articles I linked below. I hope you learned something about MVC or gained a better understanding of MVC.
Links I used
- https://medium.com/the-renaissance-developer/ruby-on-rails-http-mvc-and-routes-f02215a46a84
- https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
- https://www.codecademy.com/articles/mvc
- https://code.tutsplus.com/tutorials/mvc-for-noobs--net-10488
- https://www.ben-morris.com/what-do-we-actually-mean-when-we-say-business-logic/
- https://www.c-sharpcorner.com/article/views-in-asp-net-mvc-5/
- https://dzone.com/articles/top-10-websites-written-using-aspnet-mvc
- https://www.brainvire.com/six-benefits-of-using-mvc-model-for-effective-web-application-development/