MVCArchitecture.md - brainchildservices/curriculum GitHub Wiki

SLIDE-1

MVC ARCHITECTURE

SLIDE-2

The Model

The model defines what data the app should contain. If the state of this data changes, then the model will usually notify the view (so the display can change as needed) and sometimes the controller (if different logic is needed to control the updated view).

Going back to our shopping list app, the model would specify what data the list items should contain — item, price, etc. — and what list items are already present.

The View

The view defines how the app's data should be displayed.

In our shopping list app, the view would define how the list is presented to the user, and receive the data to display from the model.

SLIDE-2(DOWNWARDS)

The Controller

The controller contains logic that updates the model and/or view in response to input from the users of the app.

So for example, our shopping list could have input forms and buttons that allow us to add or delete items. These actions require the model to be updated, so the input is sent to the controller, which then manipulates the model as appropriate, which then sends updated data to the view.

You might however also want to just update the view to display the data in a different format, e.g., change the item order to alphabetical, or lowest to highest price. In this case the controller could handle this directly without needing to update the model.

SLIDE-3

Real Life Example of MVC 5

Suppose there is one restaurant, in this restaurant some people are working as follows:

  • Guys who are an expert cook, they works in kitchen. Guys (Manager) who take order from customer & write down that order on small paper with appropriate table number i.e one.

  • Now some customer comes into the restaurant, the guy who is going to take an order shows menu card of this restaurant to that customer.

  • Customer see this menu card. For example, customer see items such as Poha, Upma, Dosa etc. Now that customer would like to order Poha or dosa, then the customer can imagine how Poha or Dosa looks like.

image

SLIDE-4

  • After taking order from customer, that guy (Manager) give this small purchi to a man who is sitting outside the kitchen. This man who is sitting outside the kitchen is acting like a Controller in MVC, means every order is handled by this controller.

This man gives order to appropriate cook for making the order ready.

  • The cook will see the order & try to make the food ready. If he needs some extra items to make food like for Dosa he need to make 1 Chatani from coconuts then cook, visit the fridge & take this coconut & make chatani ready by adding water, sugar etc. In this scenario the cook is taking data from the database means cook is acting like Model in MVC.

image

SLIDE-5

  • After some time, the order of that customer is ready. Now the man sit outside the kitchen, calls the waiter & tell him to serve this order to the customer who ordered from table number one.

image

Now waiter adds some items to make better look & feel of food like he add some.

SLIDE-6

Now the order is ready to eat. This is actual View in MVC. Waiter is responsible for making decorate view.

image