A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Controller role in MVC?

  1. #1
    Join Date
    May 2004

    Question Controller role in MVC?

    Hi there,

    How should the controller's responsibilities be implemented in an MVC pattern?

    I'd always thought that MVC looked like this:

    Model - stores data/dispatches events

    View - listens to Model for update event(s), then changes the view as per the updated data in the Model

    Controller - listens to the view for changes, then updates the Model accordingly.

    So the Model has no references to view/controller, View has a reference to the Model and Controller has references to Model and View.

    However, I've seen a variation of the above where the view also has a reference to the Controller and calls handler methods on it directly, meaning the Controller ends up having a reference to the Model only i.e.

    Model - stores data/dispatches events

    View - listens to Model for update event(s), then changes the view as per the updated data in the Model. When the view is affected i.e. a button clicked, it calls handler methods on Controller i.e. controller.backButtonClicked()

    Controller - When handler methods are called i.e. backButtonClicked(), it updates the Model accordingly.

    Which is the correct use of the controller? The first or second example?

    I get that the 2 examples above are doing pretty much the same thing and in a way the latter example may be more efficient as a listener has been removed, but it does mean that the view becomes dependent on the controller, when I'd have thought the purpose of the controller was to act as the inbetween for the Model/View.

    Thoughts, anyone?
    He took daddy's umbrella!

  2. #2
    Junior Member
    Join Date
    Jun 2012
    You are almost saying the same thing in both cases. In first case, you are using events between View-Controller(the preferred way), where as in 2nd case you are calling the method directly. So both of the above are following MVC, first is loosely coupled using events whereas 2nd is tightly coupled.

    View: It contains your interactive view elements like button, image etc.
    Model: Acts as a database for UI.
    Controller: Take instructions from View/Model and fills Model.

    Controller explained:
    1. Model-Controller: Initially model requests data from backend through Controller. Means Controller is the agent between backend and model.
    2. View-Controller: They should always communicate through events. View dispatches and controller listens. Always update model in response to those events to maintain data integrity, which in turn should reflect in view updates, if needed.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center