c.Model View Controller (MVC)

This pattern was originally designed for thick client application but not much in use today and is of academic interest only

Web version of MVC pattern is know as MVC2

  1. Motivation

      1. This pattern allows total decoupling of Model (Data), View (Presentation/UI) and Controller(Strategy or Logic) as a result any of them can be changed at run time.

  2. Summary

      1. This pattern has three elements i.e. classes

        1. MODEL represent a business domain object.

        2. VIEW renders the data provided by model into a form suitable for interaction.

        3. CONTROLLER receives user input and initiates a response by making calls on model objects.

        4. It can be viewed as MVC=MVVM+Controller (View +Data)

  1. How it Works

      1. Though MVC comes in different flavors, control flow is generally as follows:

        1. The user interacts with the user interface in some way (for example, by pressing a mouse button).

        2. The controller handles the input event from the user interface, often via a registered handler or callback, and converts the event into an appropriate user action, understandable for the model.

        3. The controller notifies the model of the user action, possibly resulting in a change in the model's state. (For example, the controller updates the user's shopping cart.)

        4. A view queries the model in order to generate an appropriate user interface (for example the view lists the shopping cart's contents). The view gets its own data from the model. In some implementations, the controller may issue a general instruction to the view to render itself.

        5. In others, the view is automatically notified by the model of changes in state (Observer) that require a screen update.

        6. The user interface waits for further user interactions, which restarts the control flow cycle.

  2. Types of MVC Design

    1. Classic Version (MVC )

        1. Definition presented above is classic MVC or also called academic version.

        2. This version is more suitable for client application where request response time is very less. .

    2. Web MVC (MVC 2)

        1. This model is a special case of Classic MVC in which View Do not directly observe model and wait of notification from controller.

        2. This model is more stable for Web Developmental platforms like ASP.Net

  1. When to use

      1. Use this pattern if your UI transition logic is very complex and need to handle at central point.

    1. Implementation

      1. Usually you avoid using handcrafting and prefer MVC frameworks that provides out of the box implementation.

  1. Related Patterns

      1. MVC Pattern is it self consist of multiple pattern

        1. Observer : In Classic MVC view also acts as observer and listen for change notification of model

        2. Strategy:Controller uses strategy pattern to decide which view to load.

        3. Composite pattern is used by View to implement complex UI

  1. Specific Considerations