Day 16 - #100DaysofCode - Understanding MVC
Tags: ruby, 100daysofcode, womenintech, codenewbie
Published: 2020-06-17 02:14:11

<center> Table Of Contents
        [What is MVC?](#chapter-1)
        [Model](#chapter-2)
        [View](#chapter-3)
        [Controller](#chapter-4)
        [Advantages of MVC framework] (#chapter-5)
        [Resources](#chapter-6)
</center>

### What is MVC? <a name="chapter-1"></a>

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. 


### Model <a name="chapter-2"></a>

The <b>Model </b> stores data (usually from your database) and handles the logic. <i><q>It represents data that is being transferred between controller components or any other related business logic. </i></q> 

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 <a href="https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html"> BCrypt password</a> inside of the models class . 

### View <a name="chapter-3"></a>

The <b> view </b> is where the user can input information and is what the user can see. So usually your ``.erb`` or ``.html`` files. It is everything your user sees and interacts with when visiting your application.

### Controller <a name="chapter-4"></a>

The <b> Controller </b> 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 <a href="https://www.codecademy.com/articles/what-is-crud"> code academy article </a> puts it all together. 

Do you remember <a href="https://dev.to/sincerelybrittany/day-11-100daysofcode-restful-routes-1ab1">  RESTful routing</a>? 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 -- <q> 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. </q>



### What are the Advantages of MVC framework and why do we use it? <a name="chapter-5">

I read two articles <a href="https://www.whizsolutions.co.uk/advantages-using-mvc-framework-web-development/"> whizsolutions </a> and <a href="https://www.brainvire.com/six-benefits-of-using-mvc-model-for-effective-web-application-development/#:~:text=Faster%20development%20process%3A,logic%20of%20the%20web%20application"> Brainvire </a> and both indicated that these are some of the top advantages of using the MVS framework: 

<ol>
<li>Saves Time and effective use of resources – saving time, money, resources and managing the resources effectively.</li>
<li>Facilitates multiple views, separates data, and makes duplication of code is certainly less.</li>
<li>Modification does not affect the entire model </li>
<li> SEO Friendly Platform providing ease to develop SEO friendly URL’s in order to generate more visits on a specifies pages. </li>
</ol>


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. 


### Resources  <a name="chapter-4"></a>

MVC resources 
<a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"> MVC Wikipedia </a>
<a href="https://www.guru99.com/mvc-tutorial.html"> MVC Guru </a>
<a href="https://techterms.com/definition/mvc"> MVC Tech Terms </a>
<a href="https://www.tomdalling.com/blog/software-design/model-view-controller-explained/"> MVC Tom Dalling Blog </a>

CRUD resources 
<a href="https://www.codecademy.com/articles/what-is-crud"> Code Academy Article </a> 
<a href="https://dev.to/sincerelybrittany/day-9-100daysofcode-activerecord-and-a-database-6de"> Day 9: #100DaysofCode - ActiveRecord and a Database </a>
<a href= "https://dev.to/sincerelybrittany/day-10-100daysofcode-activerecord-and-a-database-17i8"> Day 10: #100DaysofCode - ActiveRecord and a Database
</a>

RESTful resources 
<a href="https://dev.to/sincerelybrittany/day-11-100daysofcode-restful-routes-1ab1">  RESTful routing </a>

Song of the day: 

{% soundcloud https://soundcloud.com/ravynlenaesounds/free-room-ft-appleby-prod-by-monte-booker %}