New to OOP

  • Thread starter Thread starter Kat
  • Start date Start date
K

Kat

I have created a class for a list of products, not too difficult actually!
I've created properties for product name, size, etc. However, each product
may have one or more categories they fit in to, such as a toothpaste may go
into grocery items and it may go under drugstore items. Do I create a
separate class for these categories, and link that class like you would the
database, a one to many? How else would I handle this, maybe a property as
a list would be better, can I do that?
 
Kat said:
I have created a class for a list of products, not too difficult actually!
I've created properties for product name, size, etc. However, each
product may have one or more categories they fit in to, such as a
toothpaste may go into grocery items and it may go under drugstore items.
Do I create a separate class for these categories, and link that class
like you would the database, a one to many? How else would I handle this,
maybe a property as a list would be better, can I do that?

I would make a separate class for the categories, with a CategoryID field
being the primary key.

Then add a property to your Product class for a corresponding instance of
Category, and a property for the category name.

Private _CategoryInstance As Category
Public Property CategoryInstance() As Category
Get
Return _CategoryInstance
End Get
Private Set(ByVal value As Category)
_CategoryInstance = value
End Set
End Property

Public ReadOnly Property CategoryName() As String
Get
Return CategoryInstance.CategoryName
End Get
End Property

Private _CategoryID As Integer
Public Property CategoryID() As Integer
Get
Return _CategoryID
End Get
Private Set(ByVal value As Integer)
'This is the Set for the CategoryID field in your
' Product class.
'When this is set, go read the database or whatever and
' populate your Category instance for that specific ID.
'Don't re-get the category description if the value hasn't changed
If _CategoryID <> value then
_CategoryID = value
CategoryInstance = Category.Create(CategoryID)
End If
End Set
End Property

The Create method in what would be my Category class would create a new
instance of Category for that ID, and go get any corresponding fields for
it and fill them in.

Hope this helps.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
I wouldn't worry about OOP

OOP makes your programs run slower; that means you 'shoudln't use it'

-Aaron
 
I wouldn't worry about OOP

OOP makes your programs run slower; that means you 'shoudln't use it'

-Aaron

Gosh, I guess you didn't write them correctly, or they would be faster. Why
don't you post some of your code, and we will help you improve its
performance?

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
Now, Robin, by his own admission, Aaron stated that he just tosses a bunch
of variants together and doesn't worry about the consequences. If the
customer wants the code to run faster and tighter, then THEY can make it
that way themselves.

Bruce
 
Do I create a
separate class for these categories, and link that class like you
would the database, a one to many? How else would I handle this,
maybe a property as a list would be better, can I do that?

Take a look at Collections and Generics - they let you store one or more
objects in a list type structure.
 
Yes, you're right (of course). How silly of me. That's right up there with
giving the users SQLServer and telling them to do their own data access.

Robin S.
----------------------------------
 
Kat,

In my idea should you not conflict OO with OOP.

Everything that you can do in VB.Net is OOP as long as you avoid shared
classes (and modules which are the same).

If you have productinformation that describes the whole class of your
products, than you can create a class Toothpasta which inherits that
productclass drugstore items..

However be aware that the current databaseservers don't work 1 at 1 with
this concept, the DataSet, DataTable concept does, however to get the above
sitation you ave to be for that a little bit more creative.

Be as well aware that by defining in classes you quick put the horse behind
the cart.

A bike has wheels
Front weels and rheer weels
Those have spokes, a different length on the brake side than on the other
side.
Spokes are divided in classes, by instance for racing and for day to day
traveling.

I can go on, but this kind of dividing is endless and in my idea without
sense

Cor
 
Yes, you're right (of course). How silly of me. That's right up there with
giving the users SQLServer and telling them to do their own data access.

Robin S.
----------------------------------
Robin/Bruce - I realize you two are thinking you are helping the
newsgroup out by engaging Aaron, but in reality you are just
encouraging him to troll more. If you must reply (like say he's
misleading a newbie), just create a single post that explains to other
viewers why he is wrong and leave it at that. This pointless taunting
going between Aaron, you, Bruce and others is subtracting from the
value of the newsgroup. After all, If you don't feed the trolls they
will go away...

Thanks,

Seth Rowe
 
Kat said:
I have created a class for a list of products, not too difficult actually!
I've created properties for product name, size, etc. However, each product
may have one or more categories they fit in to, such as a toothpaste may go
into grocery items and it may go under drugstore items. Do I create a
separate class for these categories, and link that class like you would the
database, a one to many? How else would I handle this, maybe a property as
a list would be better, can I do that?

One possible way of doing what you want is to declare interfaces to
represent the "categories" your objects fit in.

For instance:

<aircode>
Interface IGrocery
'members specific to Grocery items
End Interface

Interface IDrugstore
'members specific for Drugstore items
End Interface

Interface IVegetable
Inherits IGrocery
'...
End Interface

Class Toothpaste
Inherits Products
Implements IGrocery, IDrugstore
'...
End Class

Class Tomato
Inherits Products
Implements IVegetable
'...
End Class

Dim Vegetables As New List(Of IVegetable)
Dim Groceries As New List(Of IGrocery)
Dim DrugstoreItems As New List(Of IDrugstore)

Dim AToothPaste As New Toothpaste
Dim ATomato As New Tomato

Vegetables.Add(ATomato)
DrugstoreItems.Add(AToothPaste)
Groceries.Add(AToothPaste)
Groceries.Add(ATomato) 'How come??
</aircode>

An interface indicates that an object is of a given category and
implements a given functionality. Notice that this is strictly OOP
related, and has nothing to do with a database-wise approach.

HTH.

Regards,

Branco.
 
Thank you, Seth. I've composed several replies recently in which I was
going to make similar comments about Robin and Bruce but I chose not to send
them because I didn't want to perpetuate the problem. In my mind they are
no better than Aaron and are in fact hurting their own reputations by
lowering themselves to his level. "Grow up" is one term I use with my kids
when they act this way - it shouldn't have to be said in a professional news
group.
 
Seth,

You are, of course, correct. I don't LIKE to feed trolls, but there are
times where I feel that some kind of response is necessary to let the troll
know that their input is less than desired. It appears that I may have made
some 'trolls' of the troll, so I must apologize to the group for wasting
bandwidth on that. I'll do my best to remain out of any future conversations
with the person who desires such attention.

Bruce
 
msnews,

Thank you for 'thinking' of making such posts. Again I apologize for making
misuse of this forum. I actually came to the reallization on my own, it's
just sometimes I feel that folks who 'think' about saying something are
afraid of standing up and saying what they believe because someone will
think less of them for it. I am grateful that Seth said what he did when he
said it and I can accept admonition and move on with my life. But you
needn't tell me to 'grow up'. Handling the situation as Seth did is enough
to help anyone whose mature enough to realize it. And please, I don't want
you to think less of Robin for what he has posted against Aaron's attacks.
If his responses to Aaron, in ANY of his myriad personalities, is enough to
lessen his reputation for all the help he has given to others on this board,
then your opinion of him was none too high to begin with and that is a
shame. And since I don't have any children to tell to grow up, then my
response to you is to do as you see fit with this post.
No response is necessary.

Bruce
 
run away while you still can

OOP is for retards that listen to Microsoft

ever since Microsoft betrayed the VB community; It occurred to me that
we should 'question microsoft'
 
run away while you still can

OOP is for retards that listen to Microsoft
for starters, I have 10 books at home that all agree that 'oop makes
for more verbosity and makes code run slower'

ever since Microsoft betrayed the VB community; It occurred to me that
we should 'question microsoft'
 
hey dipshit wtf is wrong with you?

just because Aaron speaks the truth; does that mean that you MUST
discredit us?

I've got 10 books on OOP at home that consistently claim that OOP
makes:

a) more verbosity
b) slower code


only a ****ing idiot would use OOP, IMHO

-Tom
 
Kat;


you just need to use a DATABASE instead of classes and this OOP crap.
I mean seriously

PRODUCTS, PRODUCT GROUPS; ALL THAT CRAP-- ALL IT IS, IS MERELY DATA
WITHIN THE DATABASE

btw; kat you date 'nate' and you used to live with mandy??

-Tom
 
I never said that people should write their own data access.

I'm saying that end users writing queries is a lot more efficient than
having end users copy and paste, or print it out and re-enter it by
hand into a spreadsheet.

Giving each user a place to create views and sprocs is _REALLY_ basic
concept

and it's better to give them views and sprocs than queries; since ADP
makes sprocs EASIER TO WRITE than silly MDB queries

You kids are really, seriously and honestly, delusional


-Tom
 
msnews;

Why don't you STFU ?

just because your company CENSORS me it doesn't mean that it can
SILENCE me.

I am dead ****ing serious.

80% of VB6 programmers 'never wrote a class'

why do we need classes shoved down our throats?

your OOP _CRAP_ is a major roadblock to newbie developers
telling them to 'keep everything in a database and **** oop' is a
perfectly legitimate strategy.

I am so ****ing sorry that your stupid company is powerless to silence
my posts in newsgroups.

maybe Microsoft should have started a bidding war when deja went
titsup

-Tom
 
Back
Top