4 Replies Latest reply on Aug 3, 2010 10:31 AM by UbuntuPenguin

    Newbie trying to understand MVC

    christomanos

      Hi all,

       

      I am trying to understand MVC here and I have this question...

       

      I fetch some xml data from a HTTPservice but I want them to be available to all my views. Is it possible to save them in a model?

        • 1. Re: Newbie trying to understand MVC
          rootsounds Level 4

          Of course! Typically the way to go is to the parse the result of HTTPService and use it to populate some data model that makes sense for the application. You want to keep this parsing well-contained so that it can easily be changed in the event that the service is modified, but won't break your application as long as you adjust the feeds to your data model correctly.

          • 2. Re: Newbie trying to understand MVC
            christomanos Level 1

            So lets say I have this result from my service

             

            <products>
                 <product>
                      <sizes>
                           <size>24</size>
                           <size>25</size>
                           <size>26</size>
                      </sizes>
                      <colors>
                                <color>blue</color>
                                <color>red</color>
                      </colors>
                 </product>
                 <product>
                      <sizes>
                           <size>24</size>
                           <size>25</size>
                           <size>26</size>
                      </sizes>
                      <colors>
                                <color>blue</color>
                                <color>red</color>
                      </colors>
                 </product>
            </products>
            
            

             

            In this case I 'd parse this xml and I'd populate what model? What variables should my model have? public var sizes:Array; and public var colors:Array; ?

            • 3. Re: Newbie trying to understand MVC
              rootsounds Level 4

              You pull out what is useful from the result and populate whatever data model design suits your purposes.

               

              Try to find some simple examples of MVC.

              • 4. Re: Newbie trying to understand MVC
                UbuntuPenguin Level 4

                MVC stands for model-view-controller. The model is the item that generally contains your , well models.  In this case it would be your products VO's.  The view is just a view component.  The controller communicates between the view and the model. 

                 

                For instance , lets say you have a button labeled "Add Product to Cart" in your view.  When that button is clicked , the controller would here it , cobble together the data necessary ( preferably through an interface ) and send an event to the model or invoke a command on the model ( "CartModel") which would tell it to add the selected product to the cart. 

                 

                   I too was dumbfounded by the MVC/MVP paradigm.  But reading coding examples and doing toy projects helped me the most.