Proper OOP Use

I

Ivan Weiss

I am using VB.net and have a question on how to handle one aspect of OOP
programming.

I have a class for Customers, Vendors, and Employees each of which
inherits a master class, Contacts

Now on my customer center screen I want to fill a list box with all of
my customers in my database on the left and on the right have their
individual account information shown when the user selects a customer.

What is the proper way to fill the database? in VB6 days I would just
directly access the database and create a list of customers and
everytime one was selected directly call their information for the right
from the database.

With OOP should there be a class that has all of the customers in them?
Should it be a collection? Not quite sure which direction to take this
in...

Of course when I select a user I will fill my appropriate Customer class
with the customer the user selected and populate the appropriate fields
that way...

-Ivan
 
L

lord.zoltar

With OOP should there be a class that has all of the customers in them?
Should it be a collection? Not quite sure which direction to take this
in...

Both will work. I'd prefer to have a collection of customers. But if
you will be frequently working with large lists of customers it might
actually make more sense to have a CustomerList class that inherits
from list and might add one or two other properties/procedures specific
to working with large lists of customers.
 
I

Ivan Weiss

Well if I went the collection list, would you make a collection of all
of the customer objects or just pull their name or ID as a string?

If I made a collection of all customers it would use a lot more memory
for sure but at the same time a lot less database hits so it might help
performance....

I know collections are new and I have no idea how to use them... How
would I go about doing this?

-Ivan
 
R

RobinS

I have 3 projects in my solutions like this: one for Data Access,
one for Business Logic, and the UI.

The classes are in the BL layer. It calls the DAL and loads the
data into the class.

In this case, I would have a class for Customers, and I would
have another class called CustomerList. This would implement
BindingList(Of Customer) so I could bind it to a DataGridView
(or whatever) for display. I put all of the fields in it, and
use a method on the Customer class to populate the rows.

I use data binding to bind my classes to the fields on the
screen.

I can send you some sample code for the list stuff if you like;
I just posted it to the c# newsgroup, although the code is in VB.

Robin S.
 
C

Cor Ligthert [MVP]

Ivan,

Often is thought that OOP is the same as OO. I am sorry for you it is not.

In my idea are you asking an OO questions, the way how to handle
databobjects.

VB.Net is passed that way and uses an Object Oriented Programming method
which is not only about data.

If you use the standard ADO.Net methods you can only use it in an OOP way.
That can by clumsy by using it still with every small objects (item) or
effective using a lot of binding. The latter is however not influencing your
OOP way. The OOP way is that you create as much as possible instancible and
destructable objects. (The latter done by the managed code). And try to
avoid things as Modules or as they are called in VB Shared Classes (In C#
static classes and singletons).

Cor
 
I

Ivan Weiss

Robin, if you can send me some sample code that would be terrific. My
home email is (e-mail address removed)

I see what you are saying and I know the proper way is to separate data
from business rules from ui but I have never done that so have no clue
how to so some sample code might help clear the way for me...

-Ivan
 
R

RobinS

I learned how to do this from Deborah Kurata's book, "Doing Objects
in VB2005". It's coming out in March. I sent you the code that I
posted in the other ng.

Good luck.
Robin S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top