Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Jul 7, 1997

OO Programming with Databases

Question:
I am getting into the object oriented features of VB4 and I am wondering where the back-end database (such as Access) comes in for small single user applications. You can seemingly just create lots of objects with lots of properties and not bother with the relational database unless you need a multi-user product. Agreed there are not many calls for single user systems today but in a small country such as Malta (my home), many businesses are single users.

Answer:
You've asked one of the important questions of object-oriented programming -- how do I put the objects into the database? There are a couple of ways to do this.

First of all, you may want to "teach" each object how to load itself from the database. I use this method in a few places in the current application I'm using. Each individual object knows how to fill itself from the database, once it has been passed an object reference to the current database. Each object also knows how to save itself back to the database. In my case, I cause the object to save itself any time a property changes in the object. I also have an override that tells the object not to save itself immediately. This lets me do things like creating an empty object, filling it, and then telling it to save.

Another way to load/save objects is to have the collection object know how to save all the objects in one fell swoop. This takes a bit more power and will result in some unnecessary saving; however, individual actions are much faster since no database action is required when changes are made. All the changes are committed at the end.

For more information on object-oriented programming, I would highly recommend Deborah Kurata's Doing Objects in Microsoft Visual Basic 5.0. (There is also a version for Visual Basic 4.0) She goes through all these issues and many more and provides techniques for getting around these fundamental problems.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date