IV Therapy and Blood Withdrawal Course

Because this course results in 36 (CE) credit hours, each day will consist of a full day of classroom time — breaks will be offered, but will not form part of the class hours. In order to pass…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




MVC Overview

Image result for model view controller

MVC is a design pattern used to help build frameworks for applications. It is made up of three sections called the Model, View and Controller. MVC was reportedly invented by Trygve Reenskaug in the 1970's. He came up with this design as a way to describe software constructs in terms of their responsibilities and implement them effectively. It’s a popular design and is used by all types of programming languages such as Java, C#, Ruby and PHP. In this post I will go into each section and talk about what you, as a developer, should know about and include in each one. As I explain each part of the MVC model I will connect it to an analogy of a restaurant. Think of the MVC pattern as a restaurant with the Models being the cooks, Views being the customers, and Controllers being the waiters.

The model represents the data and logic of the app. A model can have a to-one and to-many relationships to other models. This is where the data is manipulated and/or saved. If any data changes, then the model will usually notify the view and sometimes the controller if different logic is needed to control the updated view. In connection with the analogy this would be the cooks. Taking meals from the waiter (the controller) and preparing meals for the customers (the view). So this would be taking data from the controller and providing the data for the view.

The view is the only part of the app the user interacts with directly. It is attached to the model and in turn displays the model’s data. It may also update the model by sending appropriate messages to it as long as it matches up with the terminology in the model. That means the view will have to know the attributes of the model it represents. With our analogy the view would be the customer. The customer places orders and receives food through the waiter but has no direct contact with the cook. This would be the user requesting certain data and the view displaying it for them however they asked for it.

The controller is the go-between for models and views. It relays data from browser to app and from app to browser. It provides users with forms and menus for inputing information. The controller receives users input and translates it, and then passes those inputs on to one or more of the views. It interprets all user actions and goes between model and view to connect them. In a restaurant a waiter taking requests from customer to cook and taking meals from cook back to customer. Without the waiter there would be no connection between the customer and cook. This would be the user requesting a certain webpage and the controller receiving the user’s request and running code based on those requests through models. Then finally responding to the user by rendering the requested view file to display the requested webpage.

Summary of MVC

An important point to remember is: The model represents the data, and does nothing else. The model does NOT depend on the controller or the view. To conclude, using the MVC pattern correctly can help you as a developer maintain and update your application with ease. On top of that it ensures a smooth and easy to follow user experience. Although it takes time, understanding why MVC works and how to properly follow it will pay off big time when creating future applications. I hope this post was helpful and if you have any questions please leave a comment!

Thank you!

Resources:

Add a comment

Related posts:

Surrounded by your scent

Tongue on salty flesh.. “Surrounded by your scent” is published by Ali Wyles in little love letters.

Feeling stressed?

Looking back at this year, many of us have changed a job. Some of us because we wanted to do so, some of us because there wasn’t any choice, and some of us may have not found the next place yet…

Tips for TOEFL iBT Reading Component

The Reading Section measures your capability to read and have an understanding of academic texts (passages) in English. Reading is a important skill in academic environment. Students have to read a…