Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 which pointed to 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
@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

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

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

Your Answer


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.