18 Replies Latest reply on Oct 10, 2008 8:11 PM by John Hall

    Communication Throughout Application and Components

    Gregory Lafrance Level 6
      Up to now my experience with Flex/AIR has been mostly small programs, studying Flex/AIR, and the joy of contributing to this forum.

      I'm now in the middle of developing my first "real" Flex/AIR app, in that it is tied to a quarterly goal, and over time others in my department will actually use it.

      I've broken the app into several MXML components, and there are components that use components, that use components (several levels of nested components).

      As you might imagine, sometimes these components need to reference variables/functions in other components, or in the main app, and I think I've done fairly well, based on my limited experience with this sort of thing (I'm not a programmer by trade, but I seem to fairly sharp ???), but I can't help think things are too tightly coupled.

      Should I be trying to push the limit in communicating between the app and the components and among the components using only events, often custom events, entirely if possible?

      I know practice makes perfect, or well, you know..., but I want to "do it right" as much as possible now.

      Thanks very much!!!
      Greg
        • 1. Re: Communication Throughout Application and Components
          Peter Lorent Level 2
          Reading your post I think: PureMVC. Its core is all about decoupling. Great for the job you are doing.
          • 2. Communication Throughout Application and Components
            g-s-b Level 1

            An "Application Framework" is what you need.
            There are many in Flex including PureMVC, Cairngorm and others.
            I found one seemingly unique in the Flex world, Mate: a "tag based" framework.

            Within Mate you can implement many design patterns, not just MVC; one of which is sure to meet your application needs and programming style.

            Mate Link: http://mate.asfusion.com/

            About Mate: http://mate.jottit.com/

            Presentation Patterns:
            http://weblogs.macromedia.com/paulw/archives/2007/09/presentation_pa.html
            http://martinfowler.com/eaaDev/SeparatedPresentation.html
            • 3. Re: Communication Throughout Application and Components
              Gregory Lafrance Level 6
              There was an email this morning asking a similar question on the Adobe internal Flex mailing list, and they mentioned Mate as well (fate???).

              This is all good info, but in that email they suggested learning flex well first, including the using events effectively, modules, etc.

              I wonder if you all might be able to comment on one of my original questions:

              "Should I be trying to push the limit in communicating between the app and the components and among the components using only events, often custom events, entirely if possible?"
              • 4. Re: Communication Throughout Application and Components
                g-s-b Level 1

                OK, although I am not the best at Flex, here is what I think.

                "Should I be trying to push the limit in communicating between the app and the components and among the components using only events, often custom events, entirely if possible?"

                No, well maybe or sure. It depends...

                There are major segments in a Flex swf: Application, UI views, components and controls... As well as different kinds of events, say user gestures and system events.

                And there are many design patterns that make the application lifecycle manageable: development, testing and maintenance.

                Design patterns differ in approach: some tightly couple a view to it's controller/model. Even there the view may be active or passive. A tightly coupled active view would simply call methods on it's associated model/controller whereas a passive view may have data pushed into it via bindings and injectors.

                The controller may use events to access services from the main application controller.

                So it is the design structure (design pattern) that guides one along with a consistent set of guidelines for the development: events vs calls vs bindings vs injectors vs observers...

                Consistence is the key. And a good proven design pattern that fits your particular application needs is the key design guide: events vs method call; passive vs active view; ...etc.

                And finally, it is often a "framework" that provides the foundation and supplies the specialized classes to ease the implementation.

                This set of articles on the "Presentation Design Pattern" is a good read and I recommend you read it for a far better understanding that I can offer. That is simply the Presentation Pattern and of course there are many others like MVC.

                Mate is simply a framework; a lib of tag elements that better enables the application of your selected design pattern into the Flex framework. It is event and injector oriented.

                Well, I hope that helps.

                • 5. Re: Communication Throughout Application and Components
                  Peter Lorent Level 2
                  Without a doubt - yes.
                  Most certainly in app's that need to last longer, it is vital to decouple as much as you can.
                  In most apps I use PureMVC and I guess the main reason is the Mediator. This class is loosely coupled to a mxml (most likely) component by way of a reference. The Mediator registers event listeners with the framework for the events it's interested in. And when receiving an event acts by using the API of the mxml component. The mxml component only dispatches events to the Mediator and the Mediator then decides what to do.
                  Today I needed to do a client change on a running app and the only thing I needed to do was modify a Mediator to listen for an event that was already broadcasted and add a public function to its mxml component.
                  In every aspect I can honestly say that an event driven app is in my point of view the way to go.
                  • 6. Re: Communication Throughout Application and Components
                    Gregory Lafrance Level 6
                    Thanks for your input Greg. I'm a little weak on design patterns. Right now I'm trying to firm up my uderstanding of MVC and possibly MVP, so I can start to introduce some of these concepts into my app.

                    Greg
                    • 7. Re: Communication Throughout Application and Components
                      Level 7

                      "Greg Lafrance" <webforumsuser@macromedia.com> wrote in message
                      news:gcl8b2$ptt$1@forums.macromedia.com...
                      > There was an email this morning asking a similar question on the Adobe
                      > internal
                      > Flex mailing list, and they mentioned Mate as well (fate???).
                      >
                      > This is all good info, but in that email they suggested learning flex well
                      > first, including the using events effectively, modules, etc.
                      >
                      > I wonder if you all might be able to comment on one of my original
                      > questions:
                      >
                      > "Should I be trying to push the limit in communicating between the app and
                      > the
                      > components and among the components using only events, often custom
                      > events,
                      > entirely if possible?"

                      That's how I've done it (bear in mind, I've only been doing this for a
                      year). I'm starting to get to the point where I want to use a framework,
                      but this is in large part because I want to write an eLearning framework and
                      I doubt I'll succeed without first understanding existing frameworks.

                      HTH;

                      Amy


                      • 8. Communication Throughout Application and Components
                        g-s-b Level 1
                        @greg - I have decided to move from an MVC/MVP model to the Presentation Model. It "feels" better to me and fits well with the kinds of applications I would like to develop.

                        @LuigiL - The presentation model eliminates the need for the mediator. The mediator in flex is really a hold over from flash developers; flex really does not need the same development techniques. But there are enough "design patterns" to go around, LOL. So whatever fits the goals best is most likely the best to employ.


                        P.S. @Greg: Mate enables the MVC and MVP patterns by not imposing a design whereas PureMVC and Cairngorm basically "impose" the MVC design. Mate also makes better use of the Flex Framework and is tag-based itself. ...just food for thought.

                        • 9. Re: Communication Throughout Application and Components
                          Gregory Lafrance Level 6
                          Here is a link that gets down to a really practical level for me. It shows an albeit simple example of taking a Flex app all in one file and breaking it into components using a simple MVC pattern. Thanks again for your help on understanding this.

                          http://clockobj.co.uk/2007/10/17/simplified-cairngorm-easy-mvc-for-adobe-flex/
                          • 10. Re: Communication Throughout Application and Components
                            Peter Lorent Level 2
                            hmm, I don't think the gang of four would agree on that Mediator part.
                            But anyway, that's beside the point. It's probably not about framework but about an event driven app. And I'm in favor of that, using a framework or not using a framework.
                            • 11. Re: Communication Throughout Application and Components
                              g-s-b Level 1

                              @Greg - Yes. Was one I started with as well. Also EasyMVC (which changed to EasyCG if I remember correctly.)

                              @ LuigiL - I do not know the "gang of four" but would suspect that you are correct if you mean that the "Mediator" is an integral part of any Cairngorm design. Point is though, that MVC is not the only "good" design pattern for Flex applications,

                              • 12. Re: Communication Throughout Application and Components
                                Peter Lorent Level 2
                                In my last post I said:
                                It's probably not about framework but about an event driven app. And I'm in favor of that, using a framework or not using a framework.
                                So, where exactly did I say that MVC is the only good design pattern? Don't put words in my mouth, ok?
                                • 13. Re: Communication Throughout Application and Components
                                  Peter Lorent Level 2
                                  >>(bear in mind, I've only been doing this for a year)
                                  Amy, from what I have seen... then you have learned a lot! Compliments for that.
                                  • 14. Re: Communication Throughout Application and Components
                                    g-s-b Level 1

                                    @ LuigiL - Sorry. I was not implying that you said "...that MVC is the only good design pattern..." I was also talking to Greg and addressing my understanding of the Cairngorm and PureMVC frameworks. And I have been at this far less time than you and my opinions are "fledgling" at best. ;-)

                                    Perhaps I should shut up now and read more for the time being.

                                    • 15. Re: Communication Throughout Application and Components
                                      Level 7

                                      "g-s-b" <webforumsuser@macromedia.com> wrote in message
                                      news:gclcpf$2aq$1@forums.macromedia.com...
                                      > @greg - I have decided to move from an MVC/MVP model to the Presentation
                                      > Model. It "feels" better to me and fits well with the kinds of
                                      > applications I
                                      > would like to develop.
                                      >
                                      > @LuigiL - The presentation model eliminates the need for the mediator.
                                      > The
                                      > mediator in flex is really a hold over from flash developers; flex really
                                      > does
                                      > not need the same development techniques. But there are enough "design
                                      > patterns" to go around, LOL. So whatever fits the goals best is most
                                      > likely
                                      > the best to employ.

                                      That is an advantage of PureMVC, IMO. It's not tied to Flex or even
                                      ActionScript.


                                      • 16. Re: Communication Throughout Application and Components
                                        g-s-b Level 1
                                        "...It's not tied to Flex or even ActionScript...."

                                        Yes. Of course. Design Patterns have been formulating for many years, long before Flex. Implementations of a Design Pattern into a specific Framework, try to optimize the implementation targeting a specific development environment and as such are tightly coupled to that underlying development environment.

                                        • 17. Re: Communication Throughout Application and Components
                                          Level 7

                                          "LuigiL" <webforumsuser@macromedia.com> wrote in message
                                          news:gclgjd$77n$1@forums.macromedia.com...
                                          >>>(bear in mind, I've only been doing this for a year)
                                          > Amy, from what I have seen... then you have learned a lot! Compliments for
                                          > that.

                                          Thanks :-). I think they call it "baptism by fire" ;-). Also known as
                                          "suuure, I can do that."


                                          • 18. Re: Communication Throughout Application and Components
                                            John Hall Level 4
                                            Good discussion for us lurkers. I've found some good articles chasing references you all provided. Thanks much.