2 Replies Latest reply on Sep 22, 2010 8:22 AM by dmclean62md

    File structure in large applications

    danielneri

      Hello,

       

      I have a fairly large application, totaling around ~150,000 lines of code.

       

      Unfortunately, when I first began building this application, my understanding of file structure and various architectural patterns was quite limited, and the code could easily be labeled as "spaghetti code."

       

      Since then, I have begun migrating everything over into an MVC structure, but was not entirely sure how to proceed.

       

      I have one primary file, let's say Application.as that is essentially the main actionscript class, and I am using 'include "com/controller/hello.as"' instead of importing classes because I did not want to clutter up my code by using classes all over the place and having to instantiate them.

       

      Would creating classes instead of having flat actionscript files be a better way to proceed?

       

      How do you structure your large applications?

       

      Are there any resources out there, articles, books, etc., that discuss enterprise level architectural patterns in Flex?

       

      Thanks!

        • 1. Re: File structure in large applications
          Claudiu Ursica Level 4

          You can go with the cairngorm 3 recomandations 4 main packages:

          -presentation

          -application

          -domain

          -infrastructure

          (go to cairgorm site for details)

           

           

          I the application is big and you feel the need you can split that even further accordint to your bussiness areas/use cases:

           

          business case 1 package

          -presentation

          -application

          -domain

          -infrastructure

           

          business case 2 package:

          -presentation

          -application

          -domain

          -infrastructure

           

          etc.

          • 2. Re: File structure in large applications
            dmclean62md

            Flex is an Object Oriented environment and so NOT using classes and objects will generally lead to the architectural anti-pattern (read Bad) sometimes refered to as the Big Ball Of Mud (aka spaghetti code).

             

            Just using classes and objects isn't always enough though. If a class is larger than 500 lines of code, it is very probably too big and doing too many things - try and split it up into smaller classes that each do exactly one thing and do it well. If a function is longer than one screen on your display, it is too big and should be broken down into smaller functions.

             

            One good indicator as to whether or not you have a good class is to use a unit testing framework (http://flexunit.org/) and write tests for the class. If it's hard to test it then it's probably still too complicated.

             

            How the classes are organized into packages is a less interesting, though if a package has more than 30 classes then there's a good chance that it's too big and you should try and divide it up.