MVC architecture

Posted by Randy Taylor on October 27, 2019

Model view controller is a software design pattern that is ubiquitous throughout software. From Sinatra and Rails in Ruby or Vue and Angular in JavaScript MVC gives you a scaffold for which to build your program. MVC lets you know how build out the complicated program in that a program is multifaceted and now you know here to put everything. The restaurant analogy is the best to relate MVC to the real world. What if you had 100 people that were hungry, 2 chefs, 1000 lbs of food, and 3 waiters at your disposal. Would you know how to deal with all that? Most likely you would set it up like a traditional restaurant to get these people fed. You wouldn’t spend time thinking about the best way or the most optimal way to do this. I’m not the only one to express this as a restaurant but I needed to reiterate because there was some confusion as to the way it is expressed elsewhere. So the Model in the MVC is literally data processing or data storage. It is 100% the part of your app or program that stores data or processes that data. In a Sinatra app I’m building my Model is a class(literally a table through Active Record) that stores data and pulls out that data when needed in the way it is needed. In my analogy it is literally the Cooks or chiefs. It processes the food and sends it back to the requester in the way it was requested. In my Sinatra app View is just what the person clicking on the website sees. It’s on the opposite end of Model. It shows the users stuff and lets them request stuff. In my Sinatra App the View is literally just the HMTL or HTML & ERB. You look at the view and make requests to the View. That’s it. The C in MVC in my Sinatra App is perfectly called controller. Here when the user sakes for things The C (Controller) does all the “get” and “post” action and is very CRUD_y. It will help put in the request to Create, help you Read, Manage your Update, and perform your Delete. In our analogy it is the waiter (what is grate is that the Model (cook) does not ever have any deleting and the Controller (waiter) can throw it away) and takes in user info and gives it to the cook, then brings what the cook processes back to the user. The most Important part of this blog post is that the Model is “data” meaning it stores user data such as user name and user password and then the Model processes that “data” if a user is trying to log in, checking if the password matches.