Skip navigation
coolik
Currently Being Moderated

MVC and Mobile projects

Dec 12, 2013 7:36 PM

Tags: #air #flex-mobile #mobile #view #flex-4.6 #model #actionscript_3.0 #4.6 #architecture #design_pattern #mvc #controller

Hi,

 

I need some guidelines about following MVC in a mobile application.

I have 2 requirements:

  1. I want to use ViewNavigators to create and destroy views,
  2. I want to do this in pure Flex, without any framework (no automated DI).

 

More precisely I'm confused about the ViewNavigator's pushView method. What should we pass as the data argument?

I think, in simple cases we pass just what the argument name suggests- pure data. Then we can handle any changes using the navigator's poppedViewReturnedObject property when popping the view. This is pretty straightforward, but what if we want to perform some operations on data (the Controller's job) without closing the view.

 

Example. Let's say we have:

  • a list, some filters and a refresh button (View)
  • a class that processes (deserializes) data received from the service (Controller)
  • and data- just what the service returns (Model)

 

I want to:

  • call the getData(filters:Array):DeserializedData method of the controller when a user clicks 'refresh' button in the View,
  • in the getData(filters:Array):DeserializedData method request data from service and deserialize,
  • pass new filtered deserialized data back to the same view.

 

My question is:

     How to call controller's getData method on button click, if the view and the controller don't know about each other?

     What would be the best approach to keep the project decoupled and data encapsulated? Any ideas?

 

  • Mixing Model (or ViewModel for someone) and Controller in one object and pass it in pushView() ?
  • Create a property in the Model, which change will be handled by the controller...?
  • Use context argument of the pushView Method to pass controller to View (I think this is not its purpose)?

 

It's very simple case and I have a feeling that I miss something very obvious.

Please share your experience.

 
Replies
  • Currently Being Moderated
    Dec 13, 2013 12:40 AM   in reply to coolik

    First of all forget about MVC and mobile being some special case in Flex - it's not.

     

    MVC in it's basic form - ignoring established frameworks - is very simple.

     

    The view displays data from one or more datasources - usually collections that allow the view to update when the content of the datacollection changes.

    User interactions with the view should be communicated with events. Events decouple the view from any controllers wishing to act on those events.

     

    A controller assigns the data sources used by the view to present it's data and listens  to events generated by the view. The controller has access to the model and will manipulate it according to events received from the view.

     

    That is basically how MVC works.

    The controller essentially connects the view with the data it presents and modifes the model according to the users interaction with the view.

    The view knows nothing about the controller.

     

    That is the core of MVC with Flex.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points