Jump to content
  • Advertisement
Sign in to follow this  
Jonny_S

[java] Proper usage of databases?

This topic is 3900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a project which requires regular database usage, I'm using the DB4O database engine but I'm not having to get too involved with it, just storage of fairly simple objects. However this is my first time really using databases and I was wondering what is the best method for interacting with my database? So far I've come up with two options: either create a database handler class, or have each class handle its own db interaction. I'm not the best at explaining things so I'll try to show an example of what I mean. Say for example I'm trying to store cars in a database, so I have a class called Car. I could have another class called DatabaseIO which has methods such as addCar(), deleteCar(), findCar() etc, or I could have static methods within the Car class to do this. I've been swaying between the two options, I think having a DatabaseIO class would probably be better, it keeps everything separate and seems a more OO way of doing things, but then again I'm pretty new to OO design. Cheers for the advice, sorry for the waffle!

Share this post


Link to post
Share on other sites
Advertisement
If you read through DB4O documentation, you'll see that it's an object database. This simply means that you tell it which objects to persist.

More specifically, the Chapter 2(PDF) of tutorial.

Share this post


Link to post
Share on other sites
Use the 'DatabaseIO' class in preference to static methods. If it starts getting bulky, split it up into multiple objects (see DAO pattern).


Share this post


Link to post
Share on other sites
Thanks for the replies, I went ahead with the single class so I'm glad to see I went with the right (or better) choice.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!