Mvc Team Howard

From Coder Merlin
Revision as of 15:30, 18 August 2021 by Devochska-sarangdevot (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Introduction

The main idea of a Model-View-Controller is designating a unique purpose to different sections of your code. The Model can be thought of as the data, the View can be thought of as the User Interface, and the Controller can be thought of as an input reader which takes the User input and decides what to do with it. The MVC model can be seen as a cycle where everything contributes to another's task and without one of them the program would be incomplete. This type of cycle is a great example of a paradigm which is a way of seeing things through a set of ideas or patterns.

Model

This contains the data stored in your program. An example of this would be a list of things. With just the list you would have no idea of what to do with the items or things on the list. A model contains no information on how to represent itself to the user, and it is the only part of the MVC that can access the database. Without the view and the controller, the model is a list with no use.

View

The view makes the program look nice, as it is mainly focused on the visual aspects that a user sees, such as the look of a button or colors on the screen. Additionally, functions that define the way users experience and use the app are located in the view section. The view knows how to access the model’s data, but does not know what the data does or how the user can affect/manipulate the data. It serves as the user interface.

Controller

Connection between the Model and View, the controller takes and interprets input from the view and updates the model by sending data to it. It is often seen as the brain of the code and connects the model and the view to produce the final product. The controller takes the input given by the user and decides what to do with it. When you interact with the program, the controller relays this information to the Model in a way it can understand, which is then sent to the View for you to see.

Advantages

The MVC allows for multiple people to work at the same time on all components, speeding up the development process and reduces the chance of accidentally affecting the view or control when editing your data, for example. The differentiation of model, view and controller also allows your code to be more reusable, and makes it easier to maintain and fix any parts of the code as you are able to target specific areas.


MVC Process

1) A user gives an input from the View, or alternatively requests information from the controller

2) This request is given to the controller

3) The controller interprets the data, and relays it to the model

4) The model manipulates the data using the logic and and framework supplied by the program

5) The model then returns the newly manipulated data to the controller

6) The controller supplies the new data to the View

7) The view uses the new data and updates the view model for the user accordingly


LINK TO IMAGE