13 Replies Latest reply on Aug 28, 2009 1:19 PM by PeakDigital

    Does this fit the M-V-C architecture?

    PeakDigital Level 1

      My goal is to build my current project with a proper MVC architecture, but I am having a bit of difficulty deciding where certain things fit in that structure.

       

      Currently I am finishing a class that saves user input. To my thinking, that best fits the "controller" portion of the structure. The class contains functions that iterate through all components in the current window (the "view" as I understand it), runs validation on the values, and compiles it into XML. Then an HTTPService is created, the XML assigned to its parameters, and then it is sent to the server.

       

      Should the compiled XML be in its own "model" class? Based on the strictest interpretation of the reading I have done on MVC, it seems so, but it doesn't seem to be an efficient method. The data is just transmitted to the server, and is not needed again.  The window is populated from an ArrayCollection "model" when it is loaded, so that data is still available for reference.

       

      Any thoughts?

       

      Thank you.

      Paul

        • 1. Re: Does this fit the M-V-C architecture?
          babo_ya Level 3

          It's hard to answer your question based on your description but, for me "it all depends..." such as whether you ever going to use that XML or not.. or i guess some other reasons..

           

          For me, keep everything simple.. you create three folders (model, control, view) and start from there.. and just remember the concept of what each item should do... model (stores data, states.. ).  and View is basically UI. and make sure there is NO direct communication between view & model. it all has to go through controllers..

           

          I built couple of Enterprise flex applications.. to me most important thing is using a right design pattern and INTERFACE!!!! (not the UI, I meant like.. type)

           

          hope this helps, but, sounds like you know more than I do...

           

          just keep everything simple..

           

          BaBo,

          • 2. Re: Does this fit the M-V-C architecture?
            kkc_mca Level 2

            Hi

             

            I am not able to uderstand from description provided by you

             

            use Cairngorm frame work to implement MVC architecture

             

            which is the best frame work recommended by adobe

             

            if this post answers your question or helps. please mark as it such

            • 3. Re: Does this fit the M-V-C architecture?
              Barna Biro Level 3

              If that's all your application will ever do then in my opinion, using MVC or any other pattern is just an overkill. Obviously, it's your decision to take but the application you have described is not of a complexity that would require the separation of the three logics ( especially if it will never change ). Patterns and meta-patterns like MVC come in handy when they bring something ( something good ) to the application and most importantly, something that is really needed. We could start abusing MVC ( and any other patterns ) to build a simple Hello World! application but does it really need it? In my opinion... No, it doesn't need it and nor does your application need it ( even if you go on and decide to try to separate things using MVC principles, it can't be called a "bad practice" just a more senseless one ).

               

              With kind regards,

              Barna Biro

              • 4. Re: Does this fit the M-V-C architecture?
                PeakDigital Level 1

                babo_ya,  I'm all for keeping it simple.  I think my project is doing OK so far as far as keeping data model and views separated. I don't follow your statement on "interface", sorry.  Oh, and I'm sure I don't know more than you. I'm very new to Flex.

                 

                kkc_mca, I have heard of Cairngorm but wanted to keep this simple, without a lot of external references. Maybe I misunderstand its use and methodology, I'll take another look.

                 

                Barna,  This is just a small part of the app. The initial release of the app will contain at least 15 different views, most of them dynamically generated (not MXML files) . The data it works with comes from a base of more than 40 tables and it's still growing. So, I want to get this right from the start.

                 

                 

                - Paul

                • 5. Re: Does this fit the M-V-C architecture?
                  Gregory Lafrance Level 6

                  My Flex 3 Cookbook post on a simple example of MVC may help:

                   

                  http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postI d=11246

                   

                  If this post answered your question or helped, please mark it as such.

                  1 person found this helpful
                  • 6. Re: Does this fit the M-V-C architecture?
                    PeakDigital Level 1

                    Greg,


                    Your Wizard MVC demo was what helped me get started on changing my project to MVC. It is a great resource. I'm just still trying to figure out a few points that haven't clicked for me yet.

                     

                    Thanks.

                    Paul

                    • 7. Re: Does this fit the M-V-C architecture?
                      Barna Biro Level 3

                      What bobo meant by interface is: you should program to an interface and not an implementation. An "interface" can be an abstract class or an actual interface ( a class using the "interface" keyword ). If these things are not clear to you then you should spend some time reading up on OOP principles.

                       

                      Once the key OOP principles are clear to you then you should step it up by reading up on Design Patterns. If you really want to get your application done correctly, then MVC is just a "minor part"... There should be more patterns involved that would help with decoupling and maybe reusability. For example, you could use the Observer pattern to achieve the desired communication between you logics. Also, you can use a Factory Method or the Abstract Factory pattern ( depending on the situation ) to create different objects/components and so on.

                       

                      I don't know how much experience you have in programming but from your posts, I'm quite sure that you are totally new to design patterns. So, if you want to get things done, then forget about finding a question to "does this fit the MVC architecture", instead, try read up on more patterns, experiment a bit with more simple applications so that you'll actually understand why certain patterns are used, where to use them and how.

                       

                      Just my 2 cents. Wishing you luck.

                      • 8. Re: Does this fit the M-V-C architecture?
                        babo_ya Level 3

                        My 2 more cents.

                         

                        Cairngorm is a piece of SXXX. It has Model & View & Controller... and stupid commands....

                        I talked trash to this guy from Adobe Steven WEbster? who claims that Caringorm is bad ***... and his Obserevalue is so bad.. the worse design pattern I ever seen.

                         

                        I'm so pissed off because I used it on an Enterprised App. and the worse design pattern ever.

                         

                         

                         

                        BaBo,

                        • 9. Re: Does this fit the M-V-C architecture?
                          Barna Biro Level 3

                          Cairgorm is definitely not the best framework out there but I wouldn't call it what you just did. It has it's purpose too. In my opinion, people should play around with such frameworks only after they already have some serious experience building applications with the help of design patterns from the ground up. Doing so, they surely have the knowledge to easily switch to whatever framework, that in the end might help speed up development time.

                           

                          But again, if you really want to learn and get things done the way you want, then you should build the whole think from the ground up without limiting yourself and the application to the things a certain framework can offer. Some frameworks are easier to extend and can be added these additional "features" but then what's the point in using the framework if you are altering it anyway?

                           

                          So, if you want to get it right and especially learn while working, then read up / learn design patterns from the ground up. You will only be successful if you actually understand what's going on in your applications and more importantly, you know why things are working the way they are ( you'll have to learn to take design decision that on the long run will help you become a better developer ).

                          • 10. Re: Does this fit the M-V-C architecture?
                            PeakDigital Level 1

                            Thanks for the additional input.

                             

                            Barna Biro,  You are correct - I have no experience with Design Patterns. Is there a book or online resource you would recommend for learning the formalities and standard methods of OOP and the patterns and methods you mentioned?

                             

                            I have learned a lot on my own, and can make just about anything work... but there are times when a broader knowledge base would be beneficial. I'm always looking to learn more.

                             

                            Thanks.

                            Paul

                            • 11. Re: Does this fit the M-V-C architecture?
                              babo_ya Level 3

                              http://www.amazon.com/Advanced-ActionScript-3-Design-Patterns/dp/0321426568

                               

                              this is my favor one. You have to fully understand what "Interface" is and how to use it before you read this.

                              And I think the author should change this book title to "how to use interface to create design patterns".

                               

                              BaBo,

                              • 12. Re: Does this fit the M-V-C architecture?
                                Barna Biro Level 3

                                I can only recommend the books I have read:

                                 

                                1) http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref= sr_1_1?ie=UTF8&s=books&qid=1251236242&sr=8-1

                                 

                                2) http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124/ref=sr_1_2?ie= UTF8&s=books&qid=1251236242&sr=8-2

                                 

                                3) http://www.amazon.com/ActionScript-3-0-Design-Patterns-Programming/dp/0596528469/ref=sr_1_ 26?ie=UTF8&s=books&qid=1251236257&sr=8-26

                                 

                                4) http://www.amazon.com/Advanced-ActionScript-3-Design-Patterns/dp/0321426568/ref=sr_1_30?ie =UTF8&s=books&qid=1251236257&sr=8-30

                                 

                                The Heads First book might not be for everyone's taste but it's a good book non the less ( a really good intro to OOP and Design Patterns ). The Gang of Four book is "the Design Patterns Bible" but it also should be the last book you read ( the terms used in the book might seem overwhelming for a beginner so you should definitely leave it as last ).

                                 

                                Don't be discouraged if you feel that you are not getting any of the things corevered in the book after reading it for the first time. If you need, read the book over and over again and most importantly EXPERIMENT! You should definitely understand why patterns are useful and when to use certain patterns ( not everything should be over-complicated with patterns if these patterns don't bring "a plus" to the application ).

                                 

                                Wishing you luck,

                                Barna Biro

                                • 13. Re: Does this fit the M-V-C architecture?
                                  PeakDigital Level 1

                                  Thank you for the book suggestions. I'll take a look at them.

                                   

                                  Paul