Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

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 http://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.

share|improve this answer
    
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 '11 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 '11 at 5:11
add comment

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).

share|improve this answer
    
AS3 with Flex/Air with a sqlite backend. –  Nate Apr 1 '11 at 0:02
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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