Re: [Flashcoders] MVC style Correction
@Ross The more and more we all talk about this, and I get to see examples, the more I would like to see a working example of yours. I really like the simplicity and flow of your idea and with your permission, like to try out your style of MVC based off your example. My idea is to leverage the MVC into just 3 classes M: V: and C: and nothing more. (I am probably crazy but this little itch I have now will not go away) But because I have a disconnect on how the MVC is applied to an actual application I can not get grips on where to start. I feel that ANY actionscript one creates should be simplistic in nature and I feel that for any project you can fit everything into just a model a view or a controller. Or at least I'd like to try and test my theory... :) Please dont call me crazy, you'll just be spinning your SWFWheels. PS: by no means am I saying that anyone else's examples are crude or wrong. I have no stance to say such. Just a heart felt feeling I have that amongst the confusion of how its done correctly, there is a simplistic solution that everyone may be overlooking. That NEO if you will. On Mar 5, 2012, at 6:05 PM, Karl DeSaulniers wrote: Thanks Cor. On Mar 5, 2012, at 4:26 AM, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) best regards Cor van Dooren The Netherlands -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: maandag 27 februari 2012 11:19 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction That actually makes a lot of sense to me and I haven't written one MVC yet. Thanks for the break-down! In relation to what Henrik said about using adaptors, I see the sub controllers as the adaptors, but they are not actually adaptors, just sub controllers with targets to the main controller. Yes? Best, Karl On Feb 27, 2012, at 1:16 AM, Ross Sclafani wrote: thanks, its just how i do MVC it really get interesting when you follow a mitosis development pattern... You start with one model, controller, and view, add features to each in parallel, and as each class gets too big, you break them out into subcontrollers, submodels, and subviews. Then sub-sub. My projects have a triple-tree structure branching out from the core model, controller, and view classes finer granularity as you reach further in, and always broken into M, V, and C: Models contain properties only. they dispatch a CHANGE Event every time one of their properties change,. Views display properties of the model. they listen for the CHANGE Event, and update their appearance with the new values stored in the model every time it changes. Controllers manipulate properties of the model. Whether trigger by event handlers in the views, or internal timers or network activity, any command that sets any value of any property of the model is placed in a controller. Controllers might use other controllers to trigger changes in submodels outside its subdomain the project starts off very compact, then grows with its functionality as required, always growing out from the center so you never paint yourself into a corner then later to optimize, you can get specific about which submodel a particular view is listening to, in turn limiting the number of change events it receives to those actually represented in the view. all subcontrollers hold a reference to the root controller, so it is easy to target any node on the controller tree from anywhere inside of it. same with the model tree. some submodel properties can emit the CHANGE Event only on a local level, and not send the event up the hierarchy, isolating the scope of view updates An MVC Example FLVPlayback is an interesting MVC component: it holds a NetStream as a model of the video it holds a Video as a view of the Video It acts as controller to set the model in motion by connecting it to a stream the ui is also a view of the video: the percent elapsed is represented n the scrub bar, ther is a play button while paused, a pause button while playing, then there are the time readouts.. if the video its playing, the user clicks pause in the view, it tells the controller to pause the stream in the model, which notifies the views, so the Video is paused, and pause button becomes a play button. thats how i do MVC. data is stored in mvc.models, data is displayed in mvc.views, and data is manipulated in mvc.controllers. Ross P. Sclafani design / technology / creative http://ross.sclafani.net http://www.twitter.com/rosssclafani http://www.linkedin.com/in/rosssclafani [347]
RE: [Flashcoders] MVC style Correction
+1 !!! Oh, would I love to see this too!! Best regards, Cor van Dooren -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: dinsdag 6 maart 2012 10:26 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction @Ross The more and more we all talk about this, and I get to see examples, the more I would like to see a working example of yours. I really like the simplicity and flow of your idea and with your permission, like to try out your style of MVC based off your example. My idea is to leverage the MVC into just 3 classes M: V: and C: and nothing more. (I am probably crazy but this little itch I have now will not go away) But because I have a disconnect on how the MVC is applied to an actual application I can not get grips on where to start. I feel that ANY actionscript one creates should be simplistic in nature and I feel that for any project you can fit everything into just a model a view or a controller. Or at least I'd like to try and test my theory... :) Please dont call me crazy, you'll just be spinning your SWFWheels. PS: by no means am I saying that anyone else's examples are crude or wrong. I have no stance to say such. Just a heart felt feeling I have that amongst the confusion of how its done correctly, there is a simplistic solution that everyone may be overlooking. That NEO if you will. On Mar 5, 2012, at 6:05 PM, Karl DeSaulniers wrote: Thanks Cor. On Mar 5, 2012, at 4:26 AM, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) best regards Cor van Dooren The Netherlands -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: maandag 27 februari 2012 11:19 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction That actually makes a lot of sense to me and I haven't written one MVC yet. Thanks for the break-down! In relation to what Henrik said about using adaptors, I see the sub controllers as the adaptors, but they are not actually adaptors, just sub controllers with targets to the main controller. Yes? Best, Karl On Feb 27, 2012, at 1:16 AM, Ross Sclafani wrote: thanks, its just how i do MVC it really get interesting when you follow a mitosis development pattern... You start with one model, controller, and view, add features to each in parallel, and as each class gets too big, you break them out into subcontrollers, submodels, and subviews. Then sub-sub. My projects have a triple-tree structure branching out from the core model, controller, and view classes finer granularity as you reach further in, and always broken into M, V, and C: Models contain properties only. they dispatch a CHANGE Event every time one of their properties change,. Views display properties of the model. they listen for the CHANGE Event, and update their appearance with the new values stored in the model every time it changes. Controllers manipulate properties of the model. Whether trigger by event handlers in the views, or internal timers or network activity, any command that sets any value of any property of the model is placed in a controller. Controllers might use other controllers to trigger changes in submodels outside its subdomain the project starts off very compact, then grows with its functionality as required, always growing out from the center so you never paint yourself into a corner then later to optimize, you can get specific about which submodel a particular view is listening to, in turn limiting the number of change events it receives to those actually represented in the view. all subcontrollers hold a reference to the root controller, so it is easy to target any node on the controller tree from anywhere inside of it. same with the model tree. some submodel properties can emit the CHANGE Event only on a local level, and not send the event up the hierarchy, isolating the scope of view updates An MVC Example FLVPlayback is an interesting MVC component: it holds a NetStream as a model of the video it holds a Video as a view of the Video It acts as controller to set the model in motion by connecting it to a stream the ui is also a view of the video: the percent elapsed is represented n the scrub bar, ther is a play button while paused, a pause button while playing, then there are the time readouts.. if the video its playing, the user clicks pause in the view, it tells the controller to pause the stream in the
Re: [Flashcoders] MVC style Correction
Forgive me if I am wrong, but I watched that video and it confused me. The gentleman started creating the view first then made the model and had the interaction between the two then went and created the controller and in creating the controller took away some code from the view that the model handled and gave it to the controller. He also had the view having reference to the model and controller. var model:Model = new Model(); var controller:Controller = new Controller(model); var view:View = new View(model, controller); shouldn't it be.. var controller:Controller = new Controller(); var model:Model = new Model(controller); var view:View = new View(model); ? Trying to wrap my head around this. Thanks for this video though Cor! It helped me see a real example so far of how to implement a MVC. Best, Karl On Mar 5, 2012, at 7:00 AM, Cor wrote: Thanks Paul, In the documentation I read there is mostly the View telling the Controller an event has taken place. The View holds e reference of the Model and the Controller. Look at : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/actions cript/pdfs/ora_as3_design_patterns_ch12.pdf on page number 429 (is the 11th page of this file) So I have create this in my Document class like this: var model:Model = Model.getInstance(); //Singleton var controller:Controller = new Controller(model); var view:View = new View(model, controller, this.stage); addChild(view); To check if I understand you correctly, you would do something like this: var model:Model = Model.getInstance(); //Singleton var view:View = new View(model, this.stage); var controller:Controller = new Controller(model, view); addChild(view); And in the view instance, instead of my way: private function btn_clickHandler(e:MouseEvent):void { controller.setValueInModel(arrayButtons.indexOf(e.target)); } private function btn_clickHandler(e:MouseEvent):void { myPublicVar = arrayButtons.indexOf(e.target); dispatchEvent(new Event(View.MY_CUSTOM_EVENT)); } Ofcourse the Controller would then have a listener : view.addEventListener( View.MY_CUSTOM_EVENT, callback_function); Correct??? Regards Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: maandag 5 maart 2012 13:31 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction On 05/03/2012 10:26, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) I don't think the controller should be updating the view. Period. Nor do I think that the view should be calling methods of the controller class. One of the main benefits of MVC is separation of concerns. Views shouldn't care about controllers, controllers should care about views. My views dispatch events about their changes and the controller listens for the events, not caring which view dispatched it. The controller updates the model, and the view listens for changes in the model. There are several ways to build the MVC pattern. The video shows one way, but really it shows a coupling that shouldn't be as tight as it is and the idea of a controller updating a view, is a no-no. Sometimes people use a micro-mvc architecture within a view to control it - no problem about that, but we should keep our MVC components as separate black boxes. Paul best regards Cor van Dooren The Netherlands -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: maandag 27 februari 2012 11:19 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction That actually makes a lot of sense to me and I haven't written one MVC yet. Thanks for the break-down! In relation to what Henrik said about using adaptors, I see the sub controllers as the adaptors, but they are not actually adaptors, just sub controllers with targets to the main controller. Yes? Best, Karl On Feb 27, 2012, at 1:16 AM, Ross Sclafani wrote: thanks, its just how i do MVC it really get interesting when you follow a mitosis development pattern... You start with one model, controller, and view, add features to each in parallel, and as each class gets too big, you break them out into subcontrollers, submodels,
RE: [Flashcoders] MVC style Correction
My guess is the view needs the reference to the controller, because it invokes function in there to update the model through the controller. I am not a OOP or MVC specialist, and know nothing more as showed in the video, so don't shoot me! -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: dinsdag 6 maart 2012 11:08 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction Forgive me if I am wrong, but I watched that video and it confused me. The gentleman started creating the view first then made the model and had the interaction between the two then went and created the controller and in creating the controller took away some code from the view that the model handled and gave it to the controller. He also had the view having reference to the model and controller. var model:Model = new Model(); var controller:Controller = new Controller(model); var view:View = new View(model, controller); shouldn't it be.. var controller:Controller = new Controller(); var model:Model = new Model(controller); var view:View = new View(model); ? Trying to wrap my head around this. Thanks for this video though Cor! It helped me see a real example so far of how to implement a MVC. Best, Karl On Mar 5, 2012, at 7:00 AM, Cor wrote: Thanks Paul, In the documentation I read there is mostly the View telling the Controller an event has taken place. The View holds e reference of the Model and the Controller. Look at : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/a ctions cript/pdfs/ora_as3_design_patterns_ch12.pdf on page number 429 (is the 11th page of this file) So I have create this in my Document class like this: var model:Model = Model.getInstance(); //Singleton var controller:Controller = new Controller(model); var view:View = new View(model, controller, this.stage); addChild(view); To check if I understand you correctly, you would do something like this: var model:Model = Model.getInstance(); //Singleton var view:View = new View(model, this.stage); var controller:Controller = new Controller(model, view); addChild(view); And in the view instance, instead of my way: private function btn_clickHandler(e:MouseEvent):void { controller.setValueInModel(arrayButtons.indexOf(e.target)); } private function btn_clickHandler(e:MouseEvent):void { myPublicVar = arrayButtons.indexOf(e.target); dispatchEvent(new Event(View.MY_CUSTOM_EVENT)); } Ofcourse the Controller would then have a listener : view.addEventListener( View.MY_CUSTOM_EVENT, callback_function); Correct??? Regards Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: maandag 5 maart 2012 13:31 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction On 05/03/2012 10:26, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) I don't think the controller should be updating the view. Period. Nor do I think that the view should be calling methods of the controller class. One of the main benefits of MVC is separation of concerns. Views shouldn't care about controllers, controllers should care about views. My views dispatch events about their changes and the controller listens for the events, not caring which view dispatched it. The controller updates the model, and the view listens for changes in the model. There are several ways to build the MVC pattern. The video shows one way, but really it shows a coupling that shouldn't be as tight as it is and the idea of a controller updating a view, is a no-no. Sometimes people use a micro-mvc architecture within a view to control it - no problem about that, but we should keep our MVC components as separate black boxes. Paul best regards Cor van Dooren The Netherlands -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: maandag 27 februari 2012 11:19 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction That actually makes a lot of sense to me and I haven't written one MVC yet. Thanks for the
RE: [Flashcoders] MVC style Correction
You could ofcourse take another approach: In the view: dispatchEvent(new Event(View.YOURVIEWEVENT)); and in the Contoller: View.addEventListener(View.YOURVIEWEVENT, callback); So there is a loose coupling as Paul wrote. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: dinsdag 6 maart 2012 11:08 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction Forgive me if I am wrong, but I watched that video and it confused me. The gentleman started creating the view first then made the model and had the interaction between the two then went and created the controller and in creating the controller took away some code from the view that the model handled and gave it to the controller. He also had the view having reference to the model and controller. var model:Model = new Model(); var controller:Controller = new Controller(model); var view:View = new View(model, controller); shouldn't it be.. var controller:Controller = new Controller(); var model:Model = new Model(controller); var view:View = new View(model); ? Trying to wrap my head around this. Thanks for this video though Cor! It helped me see a real example so far of how to implement a MVC. Best, Karl On Mar 5, 2012, at 7:00 AM, Cor wrote: Thanks Paul, In the documentation I read there is mostly the View telling the Controller an event has taken place. The View holds e reference of the Model and the Controller. Look at : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/a ctions cript/pdfs/ora_as3_design_patterns_ch12.pdf on page number 429 (is the 11th page of this file) So I have create this in my Document class like this: var model:Model = Model.getInstance(); //Singleton var controller:Controller = new Controller(model); var view:View = new View(model, controller, this.stage); addChild(view); To check if I understand you correctly, you would do something like this: var model:Model = Model.getInstance(); //Singleton var view:View = new View(model, this.stage); var controller:Controller = new Controller(model, view); addChild(view); And in the view instance, instead of my way: private function btn_clickHandler(e:MouseEvent):void { controller.setValueInModel(arrayButtons.indexOf(e.target)); } private function btn_clickHandler(e:MouseEvent):void { myPublicVar = arrayButtons.indexOf(e.target); dispatchEvent(new Event(View.MY_CUSTOM_EVENT)); } Ofcourse the Controller would then have a listener : view.addEventListener( View.MY_CUSTOM_EVENT, callback_function); Correct??? Regards Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: maandag 5 maart 2012 13:31 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction On 05/03/2012 10:26, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) I don't think the controller should be updating the view. Period. Nor do I think that the view should be calling methods of the controller class. One of the main benefits of MVC is separation of concerns. Views shouldn't care about controllers, controllers should care about views. My views dispatch events about their changes and the controller listens for the events, not caring which view dispatched it. The controller updates the model, and the view listens for changes in the model. There are several ways to build the MVC pattern. The video shows one way, but really it shows a coupling that shouldn't be as tight as it is and the idea of a controller updating a view, is a no-no. Sometimes people use a micro-mvc architecture within a view to control it - no problem about that, but we should keep our MVC components as separate black boxes. Paul best regards Cor van Dooren The Netherlands -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: maandag 27 februari 2012 11:19 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction That actually makes a lot of sense to me and I haven't written one MVC yet. Thanks for the break-down! In
Re: [Flashcoders] MVC style Correction
Bang! :) On Mar 6, 2012, at 4:21 AM, Cor wrote: My guess is the view needs the reference to the controller, because it invokes function in there to update the model through the controller. I am not a OOP or MVC specialist, and know nothing more as showed in the video, so don't shoot me! -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: dinsdag 6 maart 2012 11:08 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction Forgive me if I am wrong, but I watched that video and it confused me. The gentleman started creating the view first then made the model and had the interaction between the two then went and created the controller and in creating the controller took away some code from the view that the model handled and gave it to the controller. He also had the view having reference to the model and controller. var model:Model = new Model(); var controller:Controller = new Controller(model); var view:View = new View(model, controller); shouldn't it be.. var controller:Controller = new Controller(); var model:Model = new Model(controller); var view:View = new View(model); ? Trying to wrap my head around this. Thanks for this video though Cor! It helped me see a real example so far of how to implement a MVC. Best, Karl On Mar 5, 2012, at 7:00 AM, Cor wrote: Thanks Paul, In the documentation I read there is mostly the View telling the Controller an event has taken place. The View holds e reference of the Model and the Controller. Look at : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/ devnet/a ctions cript/pdfs/ora_as3_design_patterns_ch12.pdf on page number 429 (is the 11th page of this file) So I have create this in my Document class like this: var model:Model = Model.getInstance(); //Singleton var controller:Controller = new Controller(model); var view:View = new View(model, controller, this.stage); addChild(view); To check if I understand you correctly, you would do something like this: var model:Model = Model.getInstance(); //Singleton var view:View = new View(model, this.stage); var controller:Controller = new Controller(model, view); addChild(view); And in the view instance, instead of my way: private function btn_clickHandler(e:MouseEvent):void { controller.setValueInModel(arrayButtons.indexOf(e.target)); } private function btn_clickHandler(e:MouseEvent):void { myPublicVar = arrayButtons.indexOf(e.target); dispatchEvent(new Event(View.MY_CUSTOM_EVENT)); } Ofcourse the Controller would then have a listener : view.addEventListener( View.MY_CUSTOM_EVENT, callback_function); Correct??? Regards Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: maandag 5 maart 2012 13:31 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction On 05/03/2012 10:26, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) I don't think the controller should be updating the view. Period. Nor do I think that the view should be calling methods of the controller class. One of the main benefits of MVC is separation of concerns. Views shouldn't care about controllers, controllers should care about views. My views dispatch events about their changes and the controller listens for the events, not caring which view dispatched it. The controller updates the model, and the view listens for changes in the model. There are several ways to build the MVC pattern. The video shows one way, but really it shows a coupling that shouldn't be as tight as it is and the idea of a controller updating a view, is a no-no. Sometimes people use a micro-mvc architecture within a view to control it - no problem about that, but we should keep our MVC components as separate black boxes. Paul best regards Cor van Dooren The Netherlands -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: maandag 27 februari 2012 11:19 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction That actually makes a lot of sense to me and I haven't written one MVC yet. Thanks for the
Re: [Flashcoders] MVC style Correction
I kind of like that. I guess I am looking to the controller to do the event dispatching to the model the model to listening for the result. the view listening for changes to the model. On Mar 6, 2012, at 4:26 AM, Cor wrote: You could ofcourse take another approach: In the view: dispatchEvent(new Event(View.YOURVIEWEVENT)); and in the Contoller: View.addEventListener(View.YOURVIEWEVENT, callback); So there is a loose coupling as Paul wrote. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: dinsdag 6 maart 2012 11:08 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction Forgive me if I am wrong, but I watched that video and it confused me. The gentleman started creating the view first then made the model and had the interaction between the two then went and created the controller and in creating the controller took away some code from the view that the model handled and gave it to the controller. He also had the view having reference to the model and controller. var model:Model = new Model(); var controller:Controller = new Controller(model); var view:View = new View(model, controller); shouldn't it be.. var controller:Controller = new Controller(); var model:Model = new Model(controller); var view:View = new View(model); ? Trying to wrap my head around this. Thanks for this video though Cor! It helped me see a real example so far of how to implement a MVC. Best, Karl On Mar 5, 2012, at 7:00 AM, Cor wrote: Thanks Paul, In the documentation I read there is mostly the View telling the Controller an event has taken place. The View holds e reference of the Model and the Controller. Look at : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/ devnet/a ctions cript/pdfs/ora_as3_design_patterns_ch12.pdf on page number 429 (is the 11th page of this file) So I have create this in my Document class like this: var model:Model = Model.getInstance(); //Singleton var controller:Controller = new Controller(model); var view:View = new View(model, controller, this.stage); addChild(view); To check if I understand you correctly, you would do something like this: var model:Model = Model.getInstance(); //Singleton var view:View = new View(model, this.stage); var controller:Controller = new Controller(model, view); addChild(view); And in the view instance, instead of my way: private function btn_clickHandler(e:MouseEvent):void { controller.setValueInModel(arrayButtons.indexOf(e.target)); } private function btn_clickHandler(e:MouseEvent):void { myPublicVar = arrayButtons.indexOf(e.target); dispatchEvent(new Event(View.MY_CUSTOM_EVENT)); } Ofcourse the Controller would then have a listener : view.addEventListener( View.MY_CUSTOM_EVENT, callback_function); Correct??? Regards Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: maandag 5 maart 2012 13:31 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction On 05/03/2012 10:26, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) I don't think the controller should be updating the view. Period. Nor do I think that the view should be calling methods of the controller class. One of the main benefits of MVC is separation of concerns. Views shouldn't care about controllers, controllers should care about views. My views dispatch events about their changes and the controller listens for the events, not caring which view dispatched it. The controller updates the model, and the view listens for changes in the model. There are several ways to build the MVC pattern. The video shows one way, but really it shows a coupling that shouldn't be as tight as it is and the idea of a controller updating a view, is a no-no. Sometimes people use a micro-mvc architecture within a view to control it - no problem about that, but we should keep our MVC components as separate black boxes. Paul best regards Cor van Dooren The Netherlands -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: maandag 27 februari 2012 11:19 To: Flash
Re: [Flashcoders] MVC style Correction
More like a CMV Well its bedtime for me. Looking forward to more discussions. Best, Karl On Mar 6, 2012, at 4:35 AM, Karl DeSaulniers wrote: I kind of like that. I guess I am looking to the controller to do the event dispatching to the model the model to listening for the result. the view listening for changes to the model. On Mar 6, 2012, at 4:26 AM, Cor wrote: You could ofcourse take another approach: In the view: dispatchEvent(new Event(View.YOURVIEWEVENT)); and in the Contoller: View.addEventListener(View.YOURVIEWEVENT, callback); So there is a loose coupling as Paul wrote. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: dinsdag 6 maart 2012 11:08 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction Forgive me if I am wrong, but I watched that video and it confused me. The gentleman started creating the view first then made the model and had the interaction between the two then went and created the controller and in creating the controller took away some code from the view that the model handled and gave it to the controller. He also had the view having reference to the model and controller. var model:Model = new Model(); var controller:Controller = new Controller(model); var view:View = new View(model, controller); shouldn't it be.. var controller:Controller = new Controller(); var model:Model = new Model(controller); var view:View = new View(model); ? Trying to wrap my head around this. Thanks for this video though Cor! It helped me see a real example so far of how to implement a MVC. Best, Karl On Mar 5, 2012, at 7:00 AM, Cor wrote: Thanks Paul, In the documentation I read there is mostly the View telling the Controller an event has taken place. The View holds e reference of the Model and the Controller. Look at : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/a ctions cript/pdfs/ora_as3_design_patterns_ch12.pdf on page number 429 (is the 11th page of this file) So I have create this in my Document class like this: var model:Model = Model.getInstance(); //Singleton var controller:Controller = new Controller(model); var view:View = new View(model, controller, this.stage); addChild(view); To check if I understand you correctly, you would do something like this: var model:Model = Model.getInstance(); //Singleton var view:View = new View(model, this.stage); var controller:Controller = new Controller(model, view); addChild(view); And in the view instance, instead of my way: private function btn_clickHandler(e:MouseEvent):void { controller.setValueInModel(arrayButtons.indexOf(e.target)); } private function btn_clickHandler(e:MouseEvent):void { myPublicVar = arrayButtons.indexOf(e.target); dispatchEvent(new Event(View.MY_CUSTOM_EVENT)); } Ofcourse the Controller would then have a listener : view.addEventListener( View.MY_CUSTOM_EVENT, callback_function); Correct??? Regards Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: maandag 5 maart 2012 13:31 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction On 05/03/2012 10:26, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller- mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) I don't think the controller should be updating the view. Period. Nor do I think that the view should be calling methods of the controller class. One of the main benefits of MVC is separation of concerns. Views shouldn't care about controllers, controllers should care about views. My views dispatch events about their changes and the controller listens for the events, not caring which view dispatched it. The controller updates the model, and the view listens for changes in the model. There are several ways to build the MVC pattern. The video shows one way, but really it shows a coupling that shouldn't be as tight as it is and the idea of a controller updating a view, is a no-no. Sometimes people use a micro-mvc architecture within a view to control it - no problem about that, but we should keep our MVC components as separate black boxes. Paul best regards Cor van Dooren The Netherlands -Original Message- From:
Re: [Flashcoders] MVC style Correction
On 06/03/2012 10:35, Karl DeSaulniers wrote: I kind of like that. I guess I am looking to the controller to do the event dispatching to the model The controller manipulates the model, so it wouldn't really need to dispatch events to it. the model to listening for the result. the view listening for changes to the model. The model won't be listening for anything (though that is blurred as we progress to model persistence, which may be asynchronous - saving across a network, fetching data from a remote server, etc). View allows user interaction, View messages controller, controller updates model, view updates according to model changes. On Mar 6, 2012, at 4:26 AM, Cor wrote: You could ofcourse take another approach: In the view: dispatchEvent(new Event(View.YOURVIEWEVENT)); and in the Contoller: View.addEventListener(View.YOURVIEWEVENT, callback); So there is a loose coupling as Paul wrote. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: dinsdag 6 maart 2012 11:08 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction Forgive me if I am wrong, but I watched that video and it confused me. The gentleman started creating the view first then made the model and had the interaction between the two then went and created the controller and in creating the controller took away some code from the view that the model handled and gave it to the controller. He also had the view having reference to the model and controller. var model:Model = new Model(); var controller:Controller = new Controller(model); var view:View = new View(model, controller); shouldn't it be.. var controller:Controller = new Controller(); var model:Model = new Model(controller); var view:View = new View(model); ? Trying to wrap my head around this. Thanks for this video though Cor! It helped me see a real example so far of how to implement a MVC. Best, Karl On Mar 5, 2012, at 7:00 AM, Cor wrote: Thanks Paul, In the documentation I read there is mostly the View telling the Controller an event has taken place. The View holds e reference of the Model and the Controller. Look at : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/a ctions cript/pdfs/ora_as3_design_patterns_ch12.pdf on page number 429 (is the 11th page of this file) So I have create this in my Document class like this: var model:Model = Model.getInstance(); //Singleton var controller:Controller = new Controller(model); var view:View = new View(model, controller, this.stage); addChild(view); To check if I understand you correctly, you would do something like this: var model:Model = Model.getInstance(); //Singleton var view:View = new View(model, this.stage); var controller:Controller = new Controller(model, view); addChild(view); And in the view instance, instead of my way: private function btn_clickHandler(e:MouseEvent):void { controller.setValueInModel(arrayButtons.indexOf(e.target)); } private function btn_clickHandler(e:MouseEvent):void { myPublicVar = arrayButtons.indexOf(e.target); dispatchEvent(new Event(View.MY_CUSTOM_EVENT)); } Ofcourse the Controller would then have a listener : view.addEventListener( View.MY_CUSTOM_EVENT, callback_function); Correct??? Regards Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: maandag 5 maart 2012 13:31 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction On 05/03/2012 10:26, Cor wrote: @Karl, I just created my first MVC and it is still in progress... Lots of fun! This video helped me a lot! http://pv3d.org/2009/02/11/actionscript-3-model-view-controller-mvc/ Unfortuneatly the tutor mentions Controller can update View, but that example is not included. If anyone can give me a little example of how that is done in MVC, don't hasitate. :-) I don't think the controller should be updating the view. Period. Nor do I think that the view should be calling methods of the controller class. One of the main benefits of MVC is separation of concerns. Views shouldn't care about controllers, controllers should care about views. My views dispatch events about their changes and the controller listens for the events, not caring which view dispatched it. The controller updates the model, and the view listens for changes in the model. There are several ways to build the MVC pattern. The video shows one way, but really it shows a coupling that shouldn't be as tight as it is and the idea of a controller updating a view, is a no-no. Sometimes people use a micro-mvc architecture within a view to control it - no problem about that, but we should keep our MVC components as
Re: [Flashcoders] MVC style Correction
I guess I am looking to the controller to do the event dispatching to the model the model to listening for the result. You don't normally do that. The controller talks to the model directly, so the controller knows the model. The model doesn't know neither view nor controller and dispatches events when it changes. There's some more explaning here on MSDN (1/3 down the page, under Solution): http://msdn.microsoft.com/en-us/library/ff649643.aspx Note that they refer to this page I posted earlier: http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html - Original Message - From: Karl DeSaulniers k...@designdrumm.com To: Flash Coders List flashcoders@chattyfig.figleaf.com Sent: Tuesday, March 06, 2012 11:35 AM Subject: Re: [Flashcoders] MVC style Correction I kind of like that. I guess I am looking to the controller to do the event dispatching to the model the model to listening for the result. the view listening for changes to the model. On Mar 6, 2012, at 4:26 AM, Cor wrote: You could ofcourse take another approach: In the view: dispatchEvent(new Event(View.YOURVIEWEVENT)); and in the Contoller: View.addEventListener(View.YOURVIEWEVENT, callback); So there is a loose coupling as Paul wrote. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] MVC style Correction
I think a core concept got lost with MVC - the controller controls things. That is, it can directly update (control or talk to) a model and a view. A model should not directly update (control) anything except it's own data sources (remote or otherwise), and should only broadcast changes to anything listening, which should usually be just the controller, but sometimes a view may listen for changes too (then you have to put controller logic in the view, unless that particular view is a custom fit for the model data). A view similarly can be directly updated (controlled) by a controller, view controller, or presenter (I like that - it's a descriptive term for a view controller). For example, a controller for a list view changing the data source to a different category, or deleting an item from a view list because of remote changes, etc. A view should not directly control (or talk to) a model or a controller - it should broadcast changes to it's own state to whatever might be listening (and only controllers should be listening). So if the user hits the delete button on an item in a list view, the controller would receive a notification of some kind, and then directly tell the model to delete that item. (The glue between the controller and the view can be a bit messy in some APIs - especially the iOS API, with targets and all that.) To me having the model broadcast to the view is a shortcut - or even a short circuit - one that is justifiable in many cases, but it's good to understand that you are basically doing an end-run around the controller usually to just save some short term development time, or because you really do need a custom view for a particular model, rather than a generic view. That's how I understand MVC anyway. Kevin N. On 3/6/12 5:35 AM, Karl DeSaulniers wrote: I guess I am looking to the controller to do the event dispatching to the model the model to listening for the result. the view listening for changes to the model. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] MVC style Correction
Also, this thread has helped to flesh out my understanding of MVC to a substantial degree. I love that. :-) Kevin N. On 3/6/12 11:40 AM, Kevin Newman wrote: That's how I understand MVC anyway. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] MVC style Correction
Absolutely agree, so thank you everyone - very much. Each day I look for more. As a result of people talking about RobotLegs I bought and today received Joel Hooks' ActionScript Developers Guide to RobotLegs. A new direction - which I am thankful for. John On 06/03/2012 18:57, Kevin Newman wrote: Also, this thread has helped to flesh out my understanding of MVC to a substantial degree. I love that. :-) Kevin N. On 3/6/12 11:40 AM, Kevin Newman wrote: That's how I understand MVC anyway. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] MVC style Correction
+1 Best regards, Cor van Dooren -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of John McCormack Sent: dinsdag 6 maart 2012 21:30 To: Flash Coders List Subject: Re: [Flashcoders] MVC style Correction Absolutely agree, so thank you everyone - very much. Each day I look for more. As a result of people talking about RobotLegs I bought and today received Joel Hooks' ActionScript Developers Guide to RobotLegs. A new direction - which I am thankful for. John On 06/03/2012 18:57, Kevin Newman wrote: Also, this thread has helped to flesh out my understanding of MVC to a substantial degree. I love that. :-) Kevin N. On 3/6/12 11:40 AM, Kevin Newman wrote: That's how I understand MVC anyway. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders