3 Replies Latest reply on May 15, 2007 10:42 PM by romanczar


    romanczar Level 1

      I read some nice articles about CodeBehind "design pattern". I was wondering why this isn't used very often as it seems to be a very nice way to completely seperate logic from design, as you could have all functions ans e.g. eventListener assignments in an AS class and only arrange all visible items in an MXML derived from that class.

      Could some of the experts please provide some information about advantages or disadvantages of using CodeBehind?
          JabbyPandaUA Level 3
          The disadvantage is obvious -using code behind approach doubles the number of files.

          The more files you have in project, the harder is to maintain the project.

          We used to rely on codeBehind approach, before, but now we are back to MXML +AS mixed code approach.
            I used to separate everything into .as files as well, and you have to admit it's nice to be able to go to a single .as file that has the code dealing specifically with the area of your project, rather than scrolling up and down in your mxml/as to work with certain lines. But it is difficult to manage more files in a project...I certainly agree with Jabby in that regard. I think honestly it depends on your own sanity and preference, but moreso how many people...or "types" of people you have on a project.

            I would think that it would be easier to give one coder a few .as files to work with and then merge them with other .as files that other coders are working on into a good version control system. That way no one is really messing with the master files. However, on the flip side, a good version control system will tell you what things are different in each version of the file and then accept or deny those changes. Lastly, if you have designers and coders...meaning one strictly are graphical type Flex'ers and the others are more of your hard line Matrix code looking only folks...it also has some advantages since they can work with the graphical portion using the mxml file and your coders can do what they need in the background. The 2 then never step on each others toes while developing.

            The other issue would be "reusability". For me...and this is just me personally....I like storing certain functions and classes in external files so I can go into my class library and pull those files into new projects rather than going back into my mxml/as file and copying and pasting out of there. Just more organized IMHO. But, it basically is the same thing.

            I'm sure there's probably some other responders out there who may talk about not loading so much into a single mxml file, but rather have several so your files remain fluid and not so spaghetti looking. Anyway, probably more info than you wanted but I had to do something while I'm trying to figure out another problem.

              romanczar Level 1

              Thanks a lot for this first input. I also thought it might complicate everything more than necessary.

              The big advantage I see is the clearer seperation for the MVC Model. As AS is in the XYZClass.as, whereas all styling and layouting is in XYZ.mxml.

              But I might be wring. I think I will test it out.