I have a data layer that strictly interacts with the database and returns the result into a model. I have an asynchronous connection with the DB so sometimes I have to chain results where I have to do many queries.

I have about 1000 lines of code in a single class and It's getting hard to manage.

My question is, how do you re-factor/organize something like this? Do you break it up into multiple classes, maybe by functional area? Do you have one parent class that calls sub classes with the code in it?

Ie if you have DataAccess.class with everything in it would you break it up like this: DataAccess_FunctionalAreaA_Insert.class DataAccess_FunctionalAreaA_Update.class DataAccess_FunctionalAreaA_Delete.class DataAccess_FunctionalAreaA_Read.class

DataAccess_FunctionalAreaB_Insert.class DataAccess_FunctionalAreaB_Update.class DataAccess_FunctionalAreaB_Delete.class DataAccess_FunctionalAreaB_Read.class

I would probably use namespaces to break up the above, but I wanted to illustrate how one might break it up. What would you do?

3 Answers 3


It sounds like you are doing by hand what an Object Relational Mapper is supposed to do for you. I would therefore advise you to find a decent ORM that is already written for your platform.

Given the technologies you have listed, a quick search turned up https://stackoverflow.com/questions/3299889/best-orm-for-adobe-air-flex which pointed to http://opensource.adobe.com/wiki/display/cairngorm/How+to+Use+the+Cairngorm+Persistence+Library as a good ORM to use.

  • I will still have the same problems using an ORM. No matter what I will need a complex layer that manipulates objects, saves them, fires events on results and updates models.
    – Nate
    Apr 1, 2011 at 15:56
  • 1
    @Nate - I suspect that you do not have experience with an ORM. What you do is tell an ORM some basics about how your data is laid out and what objects are related to what others, and it creates that complex layer for you. Try it before dismissing it.
    – btilly
    Apr 2, 2011 at 5:11

What language are you using? A data access technology such as Hibernate/NHibernate/Entity framework/etc... may be helpful at reducing your data layer's size (and making it more maintainable).

  • AS3 with Flex/Air with a sqlite backend.
    – Nate
    Apr 1, 2011 at 0:02

If my application was using a single database with a good design I would do it similar to you but only one file per functional area with all the operations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.