Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Classes Why??

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
CA
Hey Everybody
I am putting together a program to store and play back my cd collection. I have 3 listboxes. The first is populated with Artist's names. When the user clicks on an artist name, a second list box displays albums by that artist. when the user clicks an on an album name a 3'rd listbox displays song titles from the album
when I populate the Artist list box I use a ado recordset and a let call inside a class to get the data from a data base. I then immediately use a get call to place the Artist name into the listbox. I repeat this process until all artists names appear in the listbox
My question?
Why bother to use classes, why not just take the Artist name striaght from the database and use the listbox.additem feature to fill the listbox
any responces on why classes are needed would be great thanks
 
If you're using OO principles in your program (UML diagrams, you know what all the classes are and how they'll interact, you've got all the flows for the forms down, etc.) then it becomes obvious why classes are used and needed.

If you aren't creating this with OO in mind, then don't bother with class modules. You won't get the full benefit, and you're better off just creating it ad-hoc.

My $.02

Jack
 
In something that simple you probably wouldn't use any classes. Classes make things much more simpler by breaking your program down into logical sections. The idea is to model your program like the real world. In larger programs classes make things easier for programmers to come behind and fix bugs, and perform upgrades. Whatever you decide is up to you as a programmer but in most cases OOP and classes it the best way to go.

Adam
 
xterra is correct, in a small application classes may add nothing. In large applications they are invaluable.

A class allows you to encapsulate all of the functionality of a thing in a single place. An added bonus of this is reusability. A well designed class can be used in lots of places.

For example, consider a logon class. Lots of applications force the user to log on. Excapsulate this in a class and voila, every time you need someone to log on, just include this class.

Now this is the best bet. Put this class in a project and build a dll - set binary compatibility.

Now, you can include a reference to that dll in all of your projects and there it is - log on functionality. And, best of all, if you improve the class (as long as you don't remove interface elements) ALL applications are improved immediately, no recompile, nothing.

Classes/DLLs are incredibly useful, but you're right - not the only way.

Chaz
 
Thanks for the reply Guys
To follow up
I have a basic understanding for the need to "break up" a program into small pieces that can work independently of one another "black boxes" might be the right term. To follow up on my question about filling a listbox with data from a database. If I understand you correctly I should be retrieving the data from the database inside a class and storing the data inside class data members. I should then filling the listbox on the form from these data memebers Correct?
In other words everything to do with connecting and retrieving/sending data from/to a database should reside inside the class not the form. The form should have no direct connection or reference to the database, only datamembers in the class
As a second year programming student understanding classes seems to be alot more work than the code needed to make them work!!
Thanks for the replys you guys rock!!
 

WROX press has a very good book (IMHO) called Professional Visual Basic 6.0 Business Objects by Rockford Lhotka. In regards to understanding classes and how to best use them in VB this book is very good.
 
I second the opinion on the WROX book. Very useful.

Chip H.
 
I will get my hands on that book thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top