Hi, I was hoping that I could get some guidance from some of you guys on Object Design with Database back ends.
I am trying to build what could be considered to be my first full scale application, which is a student tracker (simplification). While I have a reasonable idea of how I would go about designing the classes for the system, the bit that I don't know how to do is, how I would go about getting the data to and from the database.

For example with my other applications, I have done a couple of things;
1) Gathered all the data when the application started up, creating the objects then. Then when the application closed sending the data back to the database.
2) Have the code which deals with getting the data in the specific class, so the student class for example would take only one constructor argument which would be the studentID, then the class code would connect to the database and populate the object fields as appropriate.
3) Variations of the above.

I have also looked into LINQ, which seems like it would be very useful if you don't expect your classes to deal with any business logic and just data, but I suppose it would be possible to create a wrapper class that would include the business logic.

Anyway I hope that some of you guys/girls would be kind enough to either point me in the direction of some articles that maybe you have found useful on this subject or your views on what is the best methods for doing this (obviously there isn't going to be one God design pattern for this sort of thing, but some are more generic than others).

Thanks for any help/comments/suggestions in advance.

Satal :D

Recommended Answers

All 3 Replies

Thank you for your reply, unfortunately I think I must not have explained myself very clearly.
I already know how to retrieve data from a database (although I wasn't familiar with the SQLTransaction, which gives the capabilities to roll back any changes, so I will definitely have to learn more about that) and I am talking more about the behind the scenes code, rather than separating the presentation from the business logic (which is what MVC and MVP deal with).

What I was hoping to find out is; how do people have their classes get the data that is relevant to that object? So for example do people have the code that connects to the database and retrieves the data within the class or do they use another class to populate their data.

While writing that I've just realised that I should probably be using something like a factory class, providing the id for the object and then being given an instance of the object back.
Is that the method that people would recommend? If so how would people recommend getting the data back into the database and how would you deal with multi-user systems, where more than one person may be modifying data within the database at one time?
I'm sure that this is something that programmers of database systems have to deal with a lot I'm just trying to identify the most appropriate method.

Like anything in software development there is no right or wrong answer. You need to understand your requirements and future requirements and work from there.

I suggest you to read Data Access Patterns and an article - The Onion Architecture.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.